In this article, we will finish implementing the minimax algorithm for playing the 2048 game, and then we will use this implementation to automatically play a web version of this game which can be found on this Github page.

Here is the previous article about this subject, in which I showed how to represent the game state of 2048.

For that, we will first create the GameDriver class which will act as a middleman between our minimax implementation and the game found on this webpage. The GameDriver class is responsible for interacting with the game. We’ll need 2 operations to be handled: getting data about the current state of the game, and making one of the moves: up, down, left, right. These 2 operations are implemented in the following methods:

  • .getGrid() — this will get the game state data and return it as a Grid object.
  • .move() — this will take as parameter a move direction code and emulate a keypress of the appropriate arrow key.

The move direction codes that we chose in our implementation are:

  • 0 = Up
  • 1 = Down
  • 2 = Left
  • 3 = Right

#playing-2048-with-minimax #algorithms #artificial-intelligence #python #programming

How to control the game board of 2048
1.20 GEEK