UI (src/ui/)
User-interface layer. Depends on core/ and io/.
Terminal rendering (cui.jl)
Reversi.display_board — Method
display_board(game; hints=Position[])Display the current board state in the terminal. Columns are labelled a–h and rows 1–8. Optional hints highlights valid moves with a green *.
Example output
a b c d e f g h
1 · · · · · · · ·
2 · · · · · · · ·
3 · · · * · · · ·
4 · · * ○ ● · · ·
5 · · · ● ○ * · ·
6 · · · · · · · ·
7 · · · · · · · ·
8 · · · · · · · ·
Black (●): 2 White (○): 2
Current player: Black (●)Green * marks show valid moves (requires hints argument).
CUI game loop (game.jl)
Reversi.game_loop! — Method
game_loop!(game, players; on_move, on_done) -> ReversiGameRun a complete game synchronously using the given players dict (BLACK => p1, WHITE => p2).
Callbacks (both optional):
on_move(game, color, notation)– called after every move/passon_done(game)– called once when the game ends
Returns the finished ReversiGame. Does not print anything; suitable for programmatic use and testing.
Example
moves = String[]
game_loop!(ReversiGame(), Dict(BLACK => RandomPlayer(), WHITE => RandomPlayer());
on_move = (g, c, n) -> push!(moves, n))Reversi.play_game — Method
play_game(player1, player2; verbose, save_record, record_path) -> IntPlay a full game between player1 (Black) and player2 (White). Returns the winner (BLACK, WHITE, or EMPTY for draw).
Optional keyword arguments:
verbose::Bool=true– print moves and board to stdoutsave_record::Bool=false– write the game record to disk after the gamerecord_path::String– file path used whensave_record=true
Quick reference
# Human (Black) vs Random AI (White), verbose output, auto-save record
play_game(HumanPlayer(), RandomPlayer();
verbose=true, save_record=true, record_path="game.txt")
# Silent batch play (e.g. self-play data generation)
winner = play_game(MyAI(), MyAI(); verbose=false)GLMakie GUI (gui.jl)
Reversi.launch_gui — Function
launch_gui([backend=:makie], [black, white]; kwargs...)Open an interactive Reversi window. Supports multiple backends via package extensions.
Backends
:makie(default): GLMakie-based native window. Requiresusing GLMakie.:web: React-based web interface. Requiresusing Oxygen, DefaultApplication, HTTP, JSON3.
Examples
using GLMakie, Reversi
launch_gui() # human (black) vs random AI (Makie)
using Oxygen, DefaultApplication, HTTP, JSON3, Reversi
launch_gui(:web; port=8081) # start web server on port 8081Reversi.launch_replay_gui — Function
launch_replay_gui(record_or_moves; title="Game Replay")Open a read-only GLMakie replay window for a recorded game.
Requires GLMakie to be loaded first:
using GLMakie, Reversi
rec = load_game("mygame.txt")
launch_replay_gui(rec)Configuration (config.jl)
Reversi.GUIConfig — Type
GUIConfigA structure to hold GUI configuration settings.
Reversi.parse_color — Method
parse_color(hex::String)Parse a hex color string (e.g. "#RRGGBB" or "#RRGGBBAA") into a GLMakie color. Returns a tuple of (r, g, b) or (r, g, b, a) normalized to 0.0-1.0.
Launching the GUI
# Default: Human (Black) vs Random AI (White)
launch_gui()
# Fully custom
launch_gui(MyMLPlayer(model), HumanPlayer(); show_hints=false)
# Replay a saved game record
rec = load_game("game.txt")
launch_replay_gui(rec; title="My game")
# Replay a WTHOR game
_, games = read_wthor("WTH_2001.wtb")
launch_replay_gui(wthor_game_to_record(games[1]))The GUI provides:
- Player-selection menus (Human / Random AI / custom)
- Live move-history (kifu) panel
- Optional move hints and last-move highlight toggles
- Custom player registration via Julia expression (
+ Add Playerbutton)