I have recently stumbled upon the game 2048 . 我最近偶然發現了2048遊戲。 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 2
or 4
. 每次移動後,新的圖塊將出如今隨機的空白位置,值爲2
或4
。 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 2048
. 當全部盒子都裝滿而且沒有能夠合併磁貼的移動,或者您建立的值爲2048
磁貼時,遊戲終止。 git
One, I need to follow a well-defined strategy to reach the goal. 第一,我須要遵循明肯定義的策略才能實現目標。 So, I thought of writing a program for it. 所以,我想到了爲此編寫程序。 github
My current algorithm: 我當前的算法: 算法
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 }
What I am doing is at any point, I will try to merge the tiles with values 2
and 4
, that is, I try to have 2
and 4
tiles, as minimum as possible. 我正在作的是在任什麼時候候,我將嘗試合併值2
和4
的圖塊,也就是說,我嘗試將2
和4
圖塊儘量地減小。 If I try it this way, all other tiles were automatically getting merged and the strategy seems good. 若是以這種方式嘗試,全部其餘磁貼將自動合併,而且該策略看起來不錯。 app
But, when I actually use this algorithm, I only get around 4000 points before the game terminates. 可是,當我實際使用該算法時,在遊戲終止以前我只能獲得4000點。 Maximum points AFAIK is slightly more than 20,000 points which is way larger than my current score. 最高分數AFAIK略高於20,000點,這比我目前的分數還大。 Is there a better algorithm than the above? 是否有比以上更好的算法? dom