Naive decision
First, you will need a way to represent the state of the board and stack to store all the states. At each step, make a copy of the board, changed to a new state. Compare this state with all the states of the board that you encounter. If you havenโt seen it, click this state on top of the stack and continue to the next step. If you saw him, try the next step. Each level will have to try all possible 64 moves before pulling the state from the stack (backtracking). You will want to use recursion to control the state of the next transition for validation.
There are no more than 2 64 possible board configurations, which means that you can potentially continue a very long chain of unique states and still run out of memory. (For reference, 1 GB is 2 30 bytes, and a minimum of 8 bytes is required to store the board configuration). This algorithm is unlikely to complete during the life of a known universe.
You need to do something smart to reduce your search space ...
Greedy first search
You can do more by first searching for states that are closest to the allowed configuration. At each step, sort the possible moves in order from most of the lights off to a minimum. Iterate in that order. This should work reasonably well, but an optimal solution is not guaranteed.
Not all puzzles are allowed.
No matter what algorithm you use, there may be no solution, that is, you can search forever (or at least several trillion years) without finding a solution.
You will need to check the solvability fee (this is a much faster algorithm than it turns out) before spending time looking for a solution.
Beefster
source share