title: What is the optimal algorithm for the game 2048?
body: <p>I have recently stumbled upon the game <a href="http://gabrielecirulli.github.io/2048/" rel="noreferrer">2048</a>. You merge similar tiles by moving them in any of the four directions to make "bigger" tiles. After each move, a new tile appears at random empty position with a value of either <code>2</code> or <code>4</code>. The game terminates when all the boxes are filled and there are no moves that can merge tiles, or you create a tile with a value of <code>2048</code>.</p>
  
  <p>One, I need to follow a well-defined strategy to reach the goal. So, I thought of writing a program for it.</p>
  
  <p>My current algorithm:</p>
  
  <pre><code>while (!game_over) {
      for each possible move:
          count_no_of_merges_for_2-tiles and 4-tiles
      choose the move with a large number of merges
  }
  </code></pre>
  
  <p>What I am doing is at any point, I will try to merge the tiles with values <code>2</code> and <code>4</code>, that is, I try to have <code>2</code> and <code>4</code> tiles, as minimum as possible. If I try it this way, all other tiles were automatically getting merged and the strategy seems good.</p>
  
  <p>But, when I actually use this algorithm, I only get around 4000 points before the game terminates. Maximum points AFAIK is slightly more than 20,000 points which is way larger than my current score. Is there a better algorithm than the above?</p>