lights_out_game, a MATLAB code which sets up the "Lights Out" game, lighting up a few squares on a grid. An interactive user must then try to press squares in such a way that all the lights are turned off.
The Lights Out game is played on a rectangular board of squares, usually a 5x5 grid, each square containingr a light that may be on or off. Clicking the mouse on a light switches it from on to off and vice versa. However, when you switch a light, you also switch the lights to the immediate left, right, above and below.
You start the game with a randomly chosen configuration of lights and it's up to you to figure out how to get them all out.
A strategy to solve the game begins by driving all the lighted squares to the bottom row. This is done by starting in the second row, and clicking just below any light in the first row. This blacks out row 1. Repeating this process by working downwards results in turning off all the lights except in the last row.
For the 5x5 case, the strategy then depends on the pattern of lights in the bottom row. Depending on that pattern, click lights ON in the first row, and then repeat the process of driving all the lighted squares to the bottom row. This time, you should end with no lights on.
if bottom is start top as 00111 00010 01010 01001 01101 10000 10001 00011 10110 00001 11011 00100 11100 01000where, of course, "0" means a light is out, and "1" means a light is on.
The information on this web page is distributed under the MIT license.
lights_out_game is available in a C version and a C++ version and a MATLAB version.
snakes_game, a MATLAB code which simulates the game of snakes and ladders.