UI (src/ui/)

User-interface layer. Depends on core/ and io/.

Terminal rendering (cui.jl)

Reversi.display_boardMethod
display_board(game; hints=Position[])

Display the current board state in the terminal. Columns are labelled ah and rows 18. Optional hints highlights valid moves with a green *.

source

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) -> ReversiGame

Run 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/pass
  • on_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))
source
Reversi.play_gameMethod
play_game(player1, player2; verbose, save_record, record_path) -> Int

Play 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 stdout
  • save_record::Bool=false – write the game record to disk after the game
  • record_path::String – file path used when save_record=true
source

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_guiFunction
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. Requires using GLMakie.
  • :web: React-based web interface. Requires using 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 8081
source
Reversi.launch_replay_guiFunction
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)
source

Configuration (config.jl)

Reversi.parse_colorMethod
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.

source

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 Player button)