Lights Out 9x9 (or any Size from 3x3 - 9x9) - Click the Green Flag to choose your Grid Size, then - Click the Text Box to solve the All Lights ON puzzle. - [Random] generates a Random solvable puzzle. - [Reset] replays the last puzzle played. NB: See Notes below to learn how to solve Lights Out. Updated August 2022: Didn't like the grainy Stamped Sprites, so rewrote it to make all the Lights clones of the Light Sprite. Didn't need to change as much as I thought I would. Looks much better now.
Created by @gregatku for use in Coding Classes for Kids Unlimited. Inspired by @Rocket-Flier 's very popular & featured "Turn Off the Lights" project. I commented on it that the problem was that the majority of the Random (5x5) Puzzles being generated were "Unsolvable". Wanting to see if it was possible to simply generate a guaranteed solvable puzzle, I didn't want my project to duplicate @Rocket-Flier 's, so I made a fixed-size 9x9 puzzle, but later generalised it to support all grid sizes from 3x3 to 9x9. All lights clones of the Light sprite. The method I came up with to guarantee only "solvable" puzzles are generated, was to start with an all lights OFF seed pattern & simulating a random number of Light clicks. It is guaranteed to be a solvable pattern because one method of solving it (not necessarily optimal), would be to apply the simulated random Light clicks in the reverse order to which they were generated. I am delighted with the end result. I also got a lot of ideas on how to implement the game from my "Conway's Life No Clones" project. Thanks also to @colinmacc for his feedback. HOW TO SOLVE LIGHTS OUT The most widely known method for solving Lights Out is "Chasing the Lights", sometimes called "Chasing Down the Lights" because the solving rules are expressed in terms of the bottom row pattern of lights after you have chased the lights down from the top. However there is nothing stopping you chasing the lights up from the bottom, or chasing them left or right. Basically because touching a light always changes the state of the light above it, if you go across the 2nd Row and click below every light in the top row that's on, you will turn them all off. Then you repeat the process for each row until you have either solved the puzzle, or there are a few lights on in the bottom row. Then the solving rules tell you what to do (usually clicking one or more top row lights), so that the next chase down will solve the puzzle. Below are the solving rules for each of the grid sizes in order of difficulty, from hardest (8x8) to easiest (4x4). 8x8 (No generalised method for 8x8s is known to me) The rules below were discovered by me and with them I can solve any 8x8 puzzle. But you have it be able to Chase in all directions (D)own, (U)p, (L)eft & (R)ight. The only top row clicks (+) for bottom row On Lights (*) that I have been able to find are the 1st 11 below (well really only 1st 6): # Bottom Row Top Row Click (NB: --> # = giving #) 1 [*.*.*.*.] [....+...] 2 [*.*.*.**] [...+++..] 3 [.*.*.*..] [.....+..] --> 6 4 [*.......] [..+.+...] 5 [********] [...++...] 6 [.******.] [..+..+..] 7 [.*......] [...+....] --> 14 8 [*...***.] [...+....] --> 12 9 [***..***] [.+....+.] --> 12 10 [**....**] [+......+] --> 12 11 [.**..**.] [.++++++.] --> 12 12 [**.**.**] U 13 [*.*.....] R, L 14 [*.*.*...] R --> 2 15 [**.*.**.] R --> 1 16 [***.*.**] L --> 2 17 [.....*..] R --> 13 so U, D 18 [...*.*..] R --> 14 so D --> 2 19 [....***.] U --> 3 20 [....*...] R --> 19 so L --> 3 21 [*.**.***] L --> 4 22 [**..*..*] L --> 5 23 [***...**] U, R, D, U 24 [*...*...] R --> 23 so L, D, R, L 25 [.*...*..] R --> 3 26 [*.*...*.] L --> 1 27 [**.**...] R, U --> 1 28 [**..**..] R, U --> 4 29 [.*******] R --> 6 30 [...**...] U --> 10 31 [..*..*..] R, U, L --> 4 For any edge row pattern other than those above (and their mirror reflections), after the 1st Chase Down: Reset and chase in a different direction until you've either solved it or found one of the patterns above, or you've tried chasing in all 4 directions. If this doesn't give you a solve (it usually will), chase cyclically (either clockwise or anti-clockwise) until one of them appears. If the edge patterns are rotating too, put a random click on the opposite edge and chase it across, and keep cycling! Other sizes here have well known solving methods: Size Bottom Row Top Row Click 5x5 [***..] [.+...] [**.**] [..+..] [*...*] [++...] [*.**.] [....+] [.*.*.] [+..+.] 6x6 [1 on] [+ on 1, 3] [2 on] [+ on 4] [3 on] [+ on 1, 5] [4 on] [+ on 2, 6] [5 on] [+ on 3] [6 on] [+ on 4, 6] 7x7 [x on] [+ on x-1, x & x+1] 3x3 [unsolved] U, D (till solved) 9x9 [unsolved] [+........] or U 4x4 [solved] SECRET: As a reward for reading this far, here's a little secret: I've coded the 4 (On Screen or Keyboard) Arrows to do auto-chasing in the direction of the arrow. Regards Greg