Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Solving the "Move the Box" game (Programatically)

, 30 Apr 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
CodeProject 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
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... Smile | :)

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 wanna 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 this 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.

http://code.google.com/p/move-the-box-solution/

...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! Smile | :)

Enjoy Smile | :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Gilly Barr
Web Developer
Israel Israel
Started programming e-commerce sites with PHP & MySQL at the age of 14. Worked for me well for about 5 years.
 
Transfered to C# & asp.net, while serving in the IDF.
 
Currently working as a web developer for Sears Israel (SHC).
 
Check out my blog!

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 30 Apr 2012
Article Copyright 2012 by Gilly Barr
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid