datumbox/Game-2048-AI-Solver — pull request #1 by athinarayanan (2014-05-05 09:08:04+00:00)
Title: Update AIsolver.java

There is a bug in the Java code, Board.action method.
Random cell can only be added after a valid move. But in the Board.action method, random cell is added even for an invalid move.

For example,
Let the board be
0 0 0 4
0 0 0 0
0 0 0 0
0 0 0 0

AIsolver.findBestMove gives "Up" as the result, which is an invalid move, as the board does not change because of this movement.
In the Board.action method, for this invalid move, random cell is further added.

So, if we put the restriction for adding random cell only after a valid move, the present Java code will stuck on a board resulting in an invalid move (as given in the above example).

This issue is solved by checking the boardArray after move operation. If the board remains same, even after the move operation, that direction will not be used.