Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Help with internal program value selection?

Author
Message
TitoTKO
13
Years of Service
User Offline
Joined: 2nd Oct 2011
Location:
Posted: 3rd Oct 2011 02:09
Hi, I am new to the forums and am seeking help for this assignment I currently have. The main trouble I am having is figuring out how to make the program randomly select values for each card.

Here are the instruction to the assignment:

"Three cards are shown face down. Internally, the program should randomly select values for each card (one triangle, one square, and one circle). The user should be instructed to use the mouse to select which card is a triangle. The selected card should then be revealed.

Repeat this 10 times and then display the number of times the user correctly identifies the triangle card."

Any help would be greatly appreciated!

-HAVE A NICE DAY!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 3rd Oct 2011 22:48 Edited at: 3rd Oct 2011 22:50
Use the dbRND command to generate random numbers, e.g. between 0 and 2 and each number will correspond to a card. Note that you can get the same random number twice in a row, so you will need to store the choices and if the next random number was already selected, then get a new random number. After two selections, the last card can only be the third one, so that can be solved without randomizing.

I can also imagine another solution: The number of variations if you have only three cards is not so high. You could store the possible variations (e.g. ABC, ACB, BCA, etc.) in an array and then you need to generate a random number only once, to select a row from that array. Then you have the whole combination with only one random selection, and you don't even need to worry about repeating the same selection twice.

Whichever solution you choose, you will need the dbRND command, and you will also need to initialize the random number generator, for example with dbRandomize(dbTimer()). See the Dark GDK help for information about these commands.
DeadTomGC
14
Years of Service
User Offline
Joined: 11th Aug 2010
Location: LU
Posted: 18th Oct 2011 23:47
A more efficient method that will work well for any number of cards would be the following:

1.Put all the n different cards in an array.
ar1[]={1,2,3,4,5...,n}
2.Also, have a counter c=n, and make another array of length n.
ar2[]={x,x,x,x,x...,x}
3.Then take a random between 0 and c-1(cardID=dbRND(c-1))
4.Then store array 1 element cardID in array 2 element n-c.(ar2[n-c]=ar1[cardID])
5.Then take ar1[c] and put it in ar1[cardID].(ar1[cardID]=ar1[c])
6. subtract 1 from c.(c--)
Repeat 3-6 until c==0, but do not do this when c==0.

That should shuffle your deck of cards. You can now pick them in sequential order from ar2.


Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 25th Oct 2011 03:48 Edited at: 25th Oct 2011 03:48
The possible combinations are as follows:
T=triangle
O=circle
S=square

TOS or 123
STO or 312
OST or 231

SOT or 321
TSO or 132
OTS or 213

The first set shows a normal rotation of numbers and the second shows reverse rotation. Each set of 3 has it's start number and continues with it's rotation. So you have two random variables:

After this, you should be able to make the rest. It's pretty simple to make three cards using sprite images and render them to the screen. Make a fourth image for the back of the cards and assign the three sprites that image and when the guess is made simply assign the circle/square/triangle images to the respective sprites and loop it. Wash, rinse, repeat!

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-19 06:37:31
Your offset time is: 2024-11-19 06:37:31