Rust · Bitboards · Game Engine

REVERSI
ENGINE

A complete Reversi AI written in Rust. Two u64 bitboards hold the entire board state. Negamax with alpha-beta pruning and iterative deepening searches up to 11 plies deep with phase-aware evaluation.

Search Depth 3-11 plies
Board State 128 bits
Algorithm Negamax αβ
Language Rust
ABCDEFGH
2Black
2White
4 / 64 discs

01 — Under the Hood

Three layers of search intelligence.

Each technique compounds the last. Together they let the engine evaluate millions of positions across all supported depths in milliseconds.

Search

Negamax + α-β Pruning

Negamax frames the search symmetrically — the score is always from the current player's perspective. Alpha-beta pruning cuts branches that can't affect the outcome, dramatically reducing the search tree without losing accuracy.

O(b^(d/2)) avg
Ordering

Iterative Deepening

Searches depth 1 through 7 repeatedly, using the best move from the previous depth as the first candidate at the next. This move ordering makes alpha-beta cuts more effective and gives a move to play under time pressure.

Depth 1→10
Memoization

Transposition Table

A hash map keyed by the pair of black/white bitboards caches previously evaluated positions. When the same board state is reached via a different move order, the cached score is returned immediately.

(u64, u64) → score

02 — Architecture

The entire board
fits in 128 bits.

Two u64 integers — one for Black, one for White. Each bit maps to one of the 64 squares. A set bit means that player occupies that square.

Move generation uses directional bit shifts with edge masks to avoid wraparound. No loops over cells — just bitwise operations. The grids on the right update live as the animation cycles.

// board.rs

struct Board {

black: u64,

white: u64,

}

Black — u64

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

White — u64

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

03 — Evaluation

The AI thinks differently
at each phase.

A static evaluation function that doesn't adapt to game phase misleads the search. The engine shifts its priorities as the board fills.

0–20 discs

Early Game

01

Mobility

Maximise your moves, minimise opponent's

High

Corner Safety

Avoid squares adjacent to corners

High

Disc Count

Largely irrelevant this early

None

20–44 discs

Mid Game

02

Mobility

Maintain high move options

Med

Corners

Corner squares worth far more

High

Stable Discs

Edge and corner discs that can't flip

High

44–64 discs

Late Game

03

Corners

Anchors for stable formations

High

Stability

Unflippable disc count dominates

High

Disc Count

Final score — now it matters

High

04 — Play It

The engine runs in your browser.

Same Rust engine compiled to a local HTTP server. Choose your side, set the search depth, and challenge the AI. The web UI shows legal moves and full move history.

reversi-engine.vercel.app
Reversi Engine UI — game board

Side selection

Play as Black or White

Depth control

Dial AI difficulty from 3-11

Legal move hints

Highlighted cells show valid placements

Move history

Full log of every move in the game

New game

Reset and replay anytime

Challenge the EngineView Source on GitHub

MIT License · Built with Rust