https://github.com/khoda81/twenty-fourty-eight-solver
Rust-based 2048 game solver using MeanMax and MCTS algorithms, with an interactive board editor and Optuna for hyperparameter optimization.
https://github.com/khoda81/twenty-fourty-eight-solver
2048-game ai-solver expectimax game-solver mcts monte-carlo-tree-search rust
Last synced: over 1 year ago
JSON representation
Rust-based 2048 game solver using MeanMax and MCTS algorithms, with an interactive board editor and Optuna for hyperparameter optimization.
- Host: GitHub
- URL: https://github.com/khoda81/twenty-fourty-eight-solver
- Owner: khoda81
- License: mit
- Created: 2025-02-26T08:45:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-26T11:29:49.000Z (over 1 year ago)
- Last Synced: 2025-02-26T12:31:36.766Z (over 1 year ago)
- Topics: 2048-game, ai-solver, expectimax, game-solver, mcts, monte-carlo-tree-search, rust
- Language: Rust
- Homepage:
- Size: 86.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 2048 Solver
This project provides a solver for the popular [2048 game](https://play2048.co/) using various search algorithms. The solver is implemented in Rust and includes support for MeanMax and Monte Carlo Tree Search (MCTS) algorithms. Additionally, it includes a parameter search script using Optuna for hyperparameter optimization.
## Features
- **MeanMax Algorithm**: A flexible search algorithm with depth and deadline constraints.
- **Monte Carlo Tree Search (MCTS)**: A probabilistic search algorithm with exploration rate customization.
- **Interactive Board Editor**: Allows users to set up custom board configurations.
- **Parameter Search**: Uses Optuna for hyperparameter optimization.
## Installation
To build and run the project, you need to have Rust installed. You can install Rust using [rustup](https://rustup.rs/).
```sh
# Clone the repository
git clone https://github.com/yourusername/twenty-fourty-eight-solver.git
cd twenty-fourty-eight-solver
# Build the project
cargo build --release
```
## Usage
### Command Line Interface
The solver can be run from the command line with various options:
```sh
# Run the solver with default settings
cargo run --release -- --mode single-game --algorithm mcts --search-time 0.05
# Run the solver with custom depth and search time
cargo run --release -- --mode single-game --algorithm meanmax --depth 3 --search-time 2.0
```
### Interactive Board Editor
To run the solver from a given starting position you can use the terminal editor.
1. **Run the Program**: Start the program by running the main executable with the `--board-editor` flag.
```sh
cargo run --release -- --board-editor
```
2. **Edit the Board**:
- Use the arrow keys (Up, Down, Left, Right) to move the cursor around the grid.
- Use the + or = keys to increment the value of the current cell.
- Use the - key to decrement the value of the current cell.
- Use the number keys (0-9) or letter keys (a-i) to directly set the value of the current cell.
- Use the . key to clear the current cell.
- Press Enter or q to finish editing and exit the board editor.
3. **Save and Use the Board**: Once you exit the board editor, the board configuration you created will be used for the game or evaluation, depending on the mode you selected.
### Parameter Search
The parameter search script uses Optuna to find the best hyperparameters for the solver. Ensure you have Python and the required dependencies installed.
```sh
# Run the parameter search after building with cargo
python parameter-search.py
```