A solver for the 2048 game using minimax and alpha-beta pruning, as described by John Hughes in the paper "Why Functional Programming Matters".
The backend was written in Haskell using Yesod. The decisions are streamed to the browser via a websockets connection.
Demo: https://2048.diogocastro.com/
For development, use stack and either yesod or ghcid:
stack install yesod-bin --install-ghc
yesod develstack install ghcid
just ghcid-yesodFor an optimized build, use stack or nix:
stack run twenty48
nix build .#twenty48You can also cross-compile to ARM64 (e.g. to deploy to a Raspberry Pi) using nix:
nix build .#twenty48-rpiSetup a PostgreSQL database:
# with docker
source docker/dependencies.env
docker-compose up -d
# manually
sudo apt install postgresql
sudo -u postgres psql
postgres=# CREATE USER twenty48 WITH PASSWORD 'twenty48';
postgres=# CREATE DATABASE twenty48 OWNER twenty48;
postgres=# GRANT ALL PRIVILEGES ON DATABASE twenty48 TO twenty48;
postgres=# \q
# verify setup
sudo -u postgres psql -c "\l" | grep twenty48
sudo -u postgres psql -c "\du" | grep twenty48stack teststack benchOriginal game by Gabriele Cirulli.
Heuristic based on Matt Overlan's.