Skip to content

Latest commit

 

History

History
81 lines (51 loc) · 1.98 KB

README.md

File metadata and controls

81 lines (51 loc) · 1.98 KB

2048 AI

An AI (artificial intelligence) for 2048, based on a simple maximization algorithm.

To make that AI run, a 2048 engine has been built. Of the AI, there are two versions, a C++ and a Python version.

Dependencies

  • python3 (≥ 3.3)
  • python3-urwid
  • python3-numpy

Running

To just play 2048 yourself:

python3 -m g2048

To let the Python AI play a game:

python3 -m g2048 --ai

Compiling and running the C++ AI

Switch into the cpp directory and run cmake:

cmake .

Run make:

make

To let the C++ AI play a game, switch back to the upper directory and run:

python3 -m g2048 --ai --ai-command cpp/2049

Compiling and running the Rust AI

Switch into the rust directory and run make:

make run

This requires that you have a recent rustc in your PATH.

AI protocol

If you want to create a custom AI in a language of your choice, you can use this engine and let your AI talk to the engine using the AI protocol.

The AI protocol is a simple binary protocol. The host engine sends the AI 17 unsigned bytes. The first 16 bytes are the game board, with the inner loop iterating over the x axis and the outer loop over the y axis.

The seventh byte is an extension byte, which is zero for now. If it is nonzero, you’re running in a future version of the engine host and should terminate now.

The AI then has to send back the action it wants to take. This is one unsigned byte number, adhering to the following mapping:

0 => move up
1 => move down
2 => move left
3 => move right

Any other number will let the host engine ignore the request in this protocol version. In a future version, a host engine might interpret different values differently.

If the AI does not want to continue playing (e.g. because it doesn’t have any options anymore), it should just exit after having received the board.