A couple of weeks ago, some colleagues at work showed me this nice puzzle game called "Move the Box". I've seen dozens of these kinds of puzzle games in different variations, and as usual, I got hooked on it for a while.
I got stuck on a level I couldn't pass a couple of days ago, and this got my programming head thinking...
Hmmm... The board is only 6 by 7 tiles, and the levels only have up to 3 moves maximum... This shouldn't take too long for my computer to brute force through all the levels... :)
So, I got to work, and pretty easily got it solving the puzzles. It works good on the puzzles I tested it on, which include puzzles with 1, 2 and 3 possible moves to the solution. The annoying part is that you have to enter the whole map of the level you want in a two dimensional array, which can take a long time. Then, all you have to do is tell it how many moves it gets, and hit F5!
Here's a screenshot of what I see when the code solves my puzzle:
Spoiler - This is the solution to the level "Osaka 22"
I put the code up on Google code's project hosting if you want to take a look, but this should come with a disclaimer - The code is really ugly and hacky! This is only because it is a 'coding for fun' project at home, for something that will never reach any kind of production. The only thing that was important to me at the time coding was the fact that it will work. I don't see myself using this ever again. With that said, the logic of the board was still coded using classic TDD. It just seemed logical doing it that way, so it even has some cool tests.
...and if you're wondering, the answer is "yes" - This was a stupid idea, since I basically took all the fun out of playing this game for me! :)