Analysis (src/analysis/)
Position-level analysis using any Player as an evaluator. Different player types use different scoring conventions (positional weights, piece-count diff, mobility, win rate from rollouts), but evaluate_position and principal_variation return uniform JSON-serialisable shapes.
Per-move scoring and evaluation (evaluator.jl)
Reversi.evaluate_position — Method
evaluate_position(player::Player, game::ReversiGame) -> DictScore every legal move at game's current state using player. Returns a JSON-friendly dict with:
"scores"— vector of(row, col, score)named tuples"best"— best move position as(row, col)ornothing"player"— current player (BLACK or WHITE)"heatmap"— 8×8 matrix of scores for legal moves (zeros elsewhere)
Reversi.make_evaluator — Method
make_evaluator(name::AbstractString) -> PlayerConstruct an evaluator player from a short name:
"heuristic"→HeuristicPlayer()"corner"→CornerPlayer()"mobility"→MobilityPlayer()"greedy"→GreedyPlayer()"minimax-N"→MinimaxPlayer(N)(N = 1..6)"mcts-N"→MCTSPlayer(N)(N = 20..500)
Reversi.principal_variation — Method
principal_variation(player::Player, game::ReversiGame, depth::Int) -> DictTrace the "principal variation" — the sequence of moves that would be played if both sides followed player's evaluation for depth plies.
Returns a dict with:
"moves"— Vector of(row, col, notation, player)tuples, one per ply"boards"— Vector of 8×8 board snapshots after each ply (absolute encoding)"final_score"—(black, white)piece counts after the last traced move
Reversi.score_move — Function
score_move(player::Player, game::ReversiGame, move::Position) -> Float64Return a scalar score for move in the current game, according to player's evaluation. Higher is better (from the current player's perspective).
Opening book (opening_book.jl)
Zobrist-hash-keyed opening book built from WTHOR professional game data. Lookup returns aggregated statistics (game count, win split, candidate moves with frequencies) for any reached position.
Reversi.OpeningBook — Type
OpeningBookA Zobrist-hash-keyed opening book built from WTHOR professional game data.
entries: map from board hash → aggregated statisticssource_file: path of the .wtb file the book was built fromgame_count: number of WTHOR games consumedmax_depth: maximum ply depth recorded per game (book is limited to the opening)
Reversi.OpeningBookEntry — Type
OpeningBookEntryAggregated statistics for a single board position in an opening book.
total: number of games that passed through this positionblack_wins: games in which BLACK wonwhite_wins: games in which WHITE wondraws: games ending in a drawnext_moves: Dict mapping next-move notation ("f5" etc.) to play count
Reversi.build_opening_book — Method
build_opening_book(path::AbstractString; max_depth::Int=20) -> OpeningBookRead a WTHOR .wtb file and build an opening book keyed by Zobrist hash. Each game is replayed from the empty board; at each ply up to max_depth, the current position hash is used to aggregate total games, wins by colour, and next-move frequencies.
Games that fail to replay cleanly (illegal moves) are skipped.
Reversi.load_opening_book — Method
load_opening_book(path::AbstractString) -> OpeningBookDeserialize an opening book previously saved with save_opening_book.
Reversi.lookup_opening — Method
lookup_opening(book::OpeningBook, game::ReversiGame) -> Union{OpeningBookEntry,Nothing}Return the opening-book entry for the current position of game, or nothing if the position was not observed in the source data.
Reversi.opening_book_lookup_dict — Method
opening_book_lookup_dict(book::OpeningBook, game::ReversiGame) -> DictReturn a JSON-friendly lookup result for game's current position.
Reversi.opening_book_summary — Method
opening_book_summary(book::OpeningBook) -> DictReturn a JSON-friendly summary: source file, game count, entry count, max depth.
Reversi.save_opening_book — Method
save_opening_book(book::OpeningBook, path::AbstractString)Serialize book to path using Julia's Serialization stdlib.
Notes
Available evaluator names
make_evaluator accepts the following short names (used by the web API):
| Name | Player |
|---|---|
"random" | RandomPlayer() |
"greedy" | GreedyPlayer() |
"heuristic" | HeuristicPlayer() |
"corner" | CornerPlayer() |
"mobility" | MobilityPlayer() |
"minimax-N" | MinimaxPlayer(N) (N clamped to 1..6) |
"mcts-N" | MCTSPlayer(N) (N clamped to 10..5000) |
Principal variation
principal_variation traces the sequence of moves both sides would play if each followed the chosen evaluator for depth plies. The returned boards array contains absolute board snapshots after each ply, suitable for mini-board rendering in a UI.