Skip to content

dcastro/twenty48

Repository files navigation

2048 Solver

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/

Run

For development, use stack and either yesod or ghcid:

stack install yesod-bin --install-ghc
yesod devel
stack install ghcid
just ghcid-yesod

For an optimized build, use stack or nix:

stack run twenty48

nix build .#twenty48

You can also cross-compile to ARM64 (e.g. to deploy to a Raspberry Pi) using nix:

nix build .#twenty48-rpi

Database

Setup 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 twenty48

Tests and benchmarks

stack test
stack bench

Credits

Original game by Gabriele Cirulli.

Heuristic based on Matt Overlan's.

About

An AI for the 2048 game using minimax and alpha-beta pruning, as described by John Hughes in the paper "Why Functional Programming Matters". The AI was written in Haskell and runs in a Yesod backend.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors