# logique - Quel est l'algorithme optimal pour le jeu 2048

### meilleur 3 Réponses logique - Quel est l'algorithme optimal pour le jeu 2048

97

``2048: 100% 4096: 100% 8192: 100% 16384: 94% 32768: 36% ``

89

``1024 512 256 128   8   16  32  64   4   2   x   x   x   x   x   x ``
``initiateModel();  while(!game_over) {         checkCornerChosen(); // Unimplemented, but it might be an improvement to change the reference point      for each 3 possible move:         evaluateResult()     execute move with best score     if no move is available, execute forbidden move and undo, recalculateModel()  }   evaluateResult() {      calculatesBestCurrentModel()      calculates distance to chosen model      stores result  }   calculateBestCurrentModel() {       (according to the current highest tile acheived and their distribution)   } ``
`` 512 256 128  x   X   X   x   x   X   X   x   x   x   x   x   x ``
`` 512 256  64  O   8   16  32  O   4   x   x   x   x   x   x   x ``
`` 512 256 128  64   4   8  16   32   X   X   x   x   x   x   x   x ``
``  O 1024 512 256   O   O   O  128   8  16   32  64   4   x   x   x ``
``  O 1024 512 256   x   x  128 128   x   x   x   x   x   x   x   x ``

74

``@staticmethod def nextMove(board,recursion_depth=3):     m,s = AI.nextMoveRecur(board,recursion_depth,recursion_depth)     return m  @staticmethod def nextMoveRecur(board,depth,maxDepth,base=0.9):     bestScore = -1.     bestMove = 0     for m in range(1,5):         if(board.validMove(m)):             newBoard = copy.deepcopy(board)             newBoard.move(m,add_tile=True)              score = AI.evaluate(newBoard)             if depth != 0:                 my_m,my_s = AI.nextMoveRecur(newBoard,depth-1,maxDepth)                 score += my_s*pow(base,maxDepth-depth+1)              if(score > bestScore):                 bestMove = m                 bestScore = score     return (bestMove,bestScore); ``