2
\$\begingroup\$

I am trying to code a simon Game on my FPGA, and I am a bit stuck at how i should create a pattern and detect it.

simon Game : http://www.freesimon.org/

My idea until now is, I create 99 states (99 because i am implementing 99 stages). And using a random generator(which is still missing) determine what LED should be lid for each state,

then using a if statement, I check if each state(Each LED are matched to a button) match the button thats being pressed. If they match, it then checks if the next buttompress match the next state and so on.

Everytime it goes to the next state, i compare the state value with the value of stages, and if states

Could this be done smarter in some way??

\$\endgroup\$
1
  • \$\begingroup\$ What's a simon game? Is it relevant to understand how this game operates? \$\endgroup\$
    – Andy aka
    Commented Apr 12, 2014 at 12:36

2 Answers 2

3
\$\begingroup\$

I would suggest a LFSR (Linear feedback shift register). This is a pseudo random number generator. See wikipedia for details about what a LFSR is.

The only thing you have to store is the initialization vector that has to be different for each game.

For instance: You have two LFSR of 32 bits. (The LSB of each LFSR register are the output of the LFSR system). The combination of the LSB of each LFSR registers define the color to display (2bit defines 4 choices). Every time a new note has to be played, you use the two previous LFRS registers content as the initialization vector. Thus the sequence is deterministic and only defined by the very first initialization vectors. You would have no limit except the overflow of the counter of the current note in the sequence. And also the LFSR is cyclic, but with a sufficiently large register, it could repeat after only a sequence of several millions...

You don't have to save the sequence, when the player plays, you regenerate the sequence and verify that what the player is playing is identical to your sequence.

Last, but not least, LFSRs are very easy to implement in FPGAs.

\$\endgroup\$
2
  • \$\begingroup\$ Sound like a great idea, I will look in to it.. :) but how come do you want me to use a 32 bit register, Is it to get it as random as possible or?? \$\endgroup\$ Commented Apr 15, 2014 at 8:58
  • \$\begingroup\$ If you have a look at the wikipedia page about LFSR. It give standard polynomials to implement them and also the period after which it repeats. For example: 16 bits has a period of 65535. Maybe this is enough. No one would remember such a long sequence. But ok, 32 bit might be completely overkill... This was just an example. \$\endgroup\$
    – Blup1980
    Commented Apr 15, 2014 at 9:40
2
\$\begingroup\$

Since the sequence of lights/tones is going to be different each time you play the game, you should be thinking in terms of storing that sequence in a memory (block RAM inside the FPGA), so that you can read it out repeatedly, both for prompting the user and for checking their response.

You will also need a state machine, but this machine will be more about how the sequence of game-play works: initialization, generating the sequence, playing part of the light/tone sequence, waiting for the user to re-enter the sequence, etc.

\$\endgroup\$
2
  • \$\begingroup\$ The Ram seem to be a good idea to start at.. as you say I am missing the game it self. I read somewhere about the shift register, where i could use it to choose a random value.. But that part is also a bit unclear \$\endgroup\$ Commented Apr 12, 2014 at 13:24
  • \$\begingroup\$ What about using a FIFO buffer, with a dynamic size \$\endgroup\$ Commented Apr 12, 2014 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.