A high-performance Connect 4 solver using C++ bitboards, inspired by Stockfish's architecture.
- Bitboard representation - 64-bit integer board storage for blazing fast operations
- Negamax solver - Recursive algorithm to find game-theoretic optimal moves
- Alpha-Beta pruning - Skips billions of unnecessary calculations
- Transposition tables - Caches positions to avoid redundant work
- Web UI - Play against the AI in your browser (compiled to WebAssembly)
- Difficulty levels - Easy, Medium, and Hard (perfect play)
- CLI interface - Simple text-based interaction
The solver is compiled to WebAssembly and runs entirely in your browser — no server needed.
Visit marlin-xi.vercel.app to play.
| Difficulty | Search Depth | Description |
|---|---|---|
| Easy | 4 moves | Makes mistakes, great for beginners |
| Medium | 8 moves | Solid play, misses deep tactics |
| Hard | Unlimited | Perfect play — good luck! |
marlin/
├── include/ # C++ headers
│ ├── position.hpp # Bitboard position representation
│ ├── solver.hpp # Negamax solver with alpha-beta pruning
│ └── transposition.hpp # Transposition table for caching
├── src/ # C++ source files
│ ├── main.cpp # CLI interface
│ ├── position.cpp # Position implementation
│ ├── solver.cpp # Solver implementation
│ ├── transposition.cpp # Transposition table implementation
│ └── bindings.cpp # Emscripten WASM bindings
├── web/ # Web UI (static site)
│ ├── index.html # Page structure
│ ├── style.css # Styling
│ ├── app.js # Game logic
│ ├── marlin.js # Emscripten glue (generated)
│ └── marlin.wasm # WebAssembly binary (generated)
├── tests/ # Test files
├── build_wasm.bat # WASM build script (Windows)
├── vercel.json # Vercel deployment config
└── CMakeLists.txt # CMake build config (native CLI)
# Generate build files
cmake -B build -S . -G "MinGW Makefiles"
# Build
cmake --build buildRequires Emscripten SDK.
# Activate Emscripten (run once per terminal session)
D:\emsdk\emsdk_env.bat
# Build WASM
build_wasm.batThis generates web/marlin.js and web/marlin.wasm.
To test locally:
npx serve web./build/marlin| Command | Description | Example |
|---|---|---|
position [moves] |
Set up position by playing moves | position 4433 |
display |
Show the board | display |
go |
Find the best move | go |
help |
Show commands | help |
quit |
Exit | quit |
Moves are digits 1-7 representing columns:
4= Drop piece in column 4 (center)4433= P1→col4, P2→col4, P1→col3, P2→col3
> position 4433
Played 4 moves
> display
| . . . . . . . |
| . . . . . . . |
| . . . . . . . |
| . . . . . . . |
| . . O O . . . |
| . . X X . . . |
+---------------+
1 2 3 4 5 6 7
> go
Analyzing...
Column 3: score 18
bestmove 3 score 18 (WIN)
Nodes analyzed: 12847
- Positive = Current player can force a win
- Zero = Draw with perfect play
- Negative = Opponent can force a win
- Higher = Faster win
| Technique | What I Learned |
|---|---|
| Bitboards | Represent game state as bits for 100x faster operations |
| Negamax | "My opponent's loss = my gain" simplifies game tree search |
| Alpha-Beta | Skip branches that can't affect the result |
| Transposition Tables | Cache results to avoid redundant computation |
| Move Ordering | Try center columns first for better pruning |
| WebAssembly | Compile C++ to run natively in the browser |
The web UI is deployed on Vercel as a static site.
# Install Vercel CLI
npm i -g vercel
# Deploy
vercel --prodMIT