| ??? 04/18/00 16:44 Read: times |
#2255 - RE: programming a memory game |
One "trick" you need to figure out is how to get a RANDOM NUMBER. You don't need difficult mathematical algorithms for this.
The best way to do that is to have one of your timer/counters running all the time. It will quickly count repeatedly through the values 0000:FFFF again and again. Use the event of the user pressing a button to always grab a random number... even if you don't need it yet. You can always accumulate a circular list for later use. The button-technique works because the timer/counter is so quick compared to the detection or a human pressing a button. I'll not go into detail there. For example, I'll assume you need to randomly choose a number between 1 and 6. As you read the timer/counter you can throw away the upper byte value, retaining only the value from 00:FF. Be careful here. Many people use a shortcut that corrupts the equal distribution requirements of random numbers. [BAD IDEA: Some would strip off higher order bits to reduce the number down to 00 to 07 and if its out of range, try for another number.] Use the DIVIDE command: Move the 00:FF byte value into the accumulator, and move a special value "X" into the B Register. Divide A by B and your number will be in the A register (the integer portion of the quotient). Use it as your zero-relative random number. The Special value is int(256/X) where X is the range of your random selection. In the example of a number between 1:6, you take the number 256 and dividing in into 6 classes, each 42 or 43 in length. By dividing the 00:FF number by 42 or 43, you get a result in Register A in the range 00:05. Of course, you could also design a way to select by different probability distribution curves but that's another topic. Keep in mind this doesn't work well for "rolling two dice" because the odds are different than an equal distribution among 1:12. You need two independent user events to get two numbers or the circular buffer list of random nubmers accumulated by earlier button pushes. Remember that the instant the user presses the button is the event that grabs the quickly countering timer value and that event is considered the randomizer in this approach. If you need something fancier, let me know. -Jay C. Box |
| Topic | Author | Date |
| programming a memory game | 01/01/70 00:00 | |
| RE: programming a memory game | 01/01/70 00:00 | |
| RE: programming a memory game | 01/01/70 00:00 | |
RE: programming a memory game | 01/01/70 00:00 |



