lunes, 26 de marzo de 2012

Slide Puzzle


For my third game I wanted to try some 3D and so here it is in isometric projection. As you can appreciate this is no normal slide puzzle as there are two empty spaces and there is no unique solution. The rules are simple:
  • Try to make a path from the left circle to the right by moving the arrows on the table.
  • A tile can only move if there is one and only one empty space beside it. 
  • The arrow on the clicked tile indicates the direction in which the other empty space will move.
Good luck!

Tiles


This game is circular puzzle in which the original figure is messed up, you have to click on the circles to return to the original state. I introduced a rule to make it a little more interesting, when a circle has two and only two lobes of the same color the normal rotation is modified from 90º to 180º. More instructions on the game itself.

Flood It!



Here is my version of the popular "Flood It!" game for Android. I played the game a lot on my phone and always wondered if there was an algorithm that could find the best solution for any "Flood It!" game, then I found this article that demonstrates the problem is NP-hard for boards of height 3 or more. That did not stop me and I tried to build the best algorithm I could. I decided to program it in JavaScript because I wanted to learn a new language and wanted it to be available to anyone. I implemented the game and the following algorithms:

  • Greedy Approach. Pick the colour that results in the largest gain (number of acquired tiles). The number of moves for this approach is calculated for every new table. The colour with the black wide border is the one that gives the largest gain at any stage.
  • Force (Brute force approach). Typical brute force algorithm, tries all the combinations and returns the solution with the minimum moves. It can take very long for tables of more than 3 colours.
  • SD  (Shortest Distance). To undestand this algorithm and SD2 we have to define the shortest distance to a tile, this value is the minimum number of moves needed to flood a concrete tile. In this approach at each stage we calculate the matrix of shortest distances after choosing every next colour. The color which gives the table which sum is minimum is the color we pick.
  • SD2 (Shortest Distance 2). In this approach at each stage we calculate the matrix of shortest distances before and after choosing every next colour. Then we compare only the maximun values. The color which reduces the most the maximum values in the shortest distance matrix is the chosen one. This is my best try but is difficult to compare to the optimal solution as the force approach takes too much time.
The solutions are displayed on the left pane using numbers, 1 for red, 2 for yellow ... moreover you can play pressing the numbers on the keyboard.