Lights Out Game

Jul 8, 2008 at 6:58am
Greetings to all.

I am trying to find a way to generate via C++ code new lists for a "Lights Out" simple game.

If you don't know what Lights Out is the premise is you have a 5 x 5 board

0 0 0 0 0
0 0 0 1 0
1 1 0 1 1
0 1 1 0 0
1 1 1 1 1

1 being the light on 0 being a light off. When you turn a light on or off every light that is connected to it up, down, left, right will turn to its opposite. The objective is to eliminate all of the lights to make the board go dark.

If you try to just generate a board thru something like rand you won't necessarily get a viable solveable puzzle. Does anyone know a way for me to generate viable games? I wouldn't even mind a seperate program that wrote out a handful that could be used later as input.
Jul 8, 2008 at 7:31am
I've not seen this game before, but my first thoughts on generating a solvable board woudl be to start with a board whith all lights off, then turn on lights at random to 'scramble' the board - if you follow the rules for switching lights when you do this then you will have a soluble board when finished.
So you use rand to decide how many lights to turn on (or off), and which lights these will be.
Should be resaonably easy to code:-)
Jul 8, 2008 at 7:34am
closed account (z05DSL3A)
Start with a blank board, then randomly select a position on the board and switch it, do the normal logic for switching the positions around the selected position. Do this a random number of times. You should then have a board that can be solved, but is randomly created.

Edit: beaten to it
Last edited on Jul 8, 2008 at 7:35am
Topic archived. No new replies allowed.