Electronic – How to implement Lights-Out game using logic gates or flip flops


First, for those unfamiliar with the game, this is how the game works,

game play

The goal of the game is to turn off all the lights, hence called "Lights Out", and each press of the button/light inverses its state as well as its north/south/east/west adjacent neighbors, and that's pretty much it.

Now, what I could think of is by using SR flip-flops, or JK flip flops. This is due to its ability to act as storage element (the initial state and next state). But I can't seem to think of ways to actually implement them.

Another idea is that each set of button and its adjacent (NSEW)button/lights will have its own truth table, like this:

logic table

but, is it possible to have the input variables be the same as the output variables? Are there any other ways to do this?

Best Answer

The obvious approach would be to use a processor and do all this in firmware.

However, if I really needed to do this with stone knives and bear skins for some reason, I'd dedicate a toggling flip-flop to each square. The flip flop of each square would be toggled by the press of its button or either of the four neighboring buttons. Of course those button presses need to be de-bounced. Again, this would be easier in firmware.

A hardware solution wouldn't be all that complex, but everything would be replicated 25 times, making it large and tedius to build.


Apparently the description above is not clear enough. Here is a diagram of what is in each cell:

The other 4 inputs to the NAND gate are driven from the debounced signals of the 4 surrounding buttons that are also supposed to toggle the state of this square. Likewise, the debounced signal from this button also goes to one of the NAND gate inputs of each of the 4 surrounding cells.