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.kifu_row_atMethod
kifu_row_at(y::Real) -> Int

Row lying under the y coordinate y, the inverse of kifu_row_y. A result outside 1:n_rows means the point is off the list; callers must reject it, nothing is clamped here.

source
Reversi.kifu_row_limitsMethod
kifu_row_limits(n_rows::Integer) -> Tuple{Float32,Float32}

Axis range showing all n_rows rows with half a row of padding, high value first so the list reads downwards. Pass straight to ylims!.

source
Reversi.kifu_row_yMethod
kifu_row_y(n::Integer) -> Float32

Y coordinate of the top-anchored move-list row n, so row n covers the half-open band [kifu_row_y(n), kifu_row_y(n + 1)).

Forms a set with kifu_row_at and kifu_row_limits, which only mean anything together: a backend that draws with one convention, hit-tests with another, or sizes its axis to a third silently mis-selects moves or clips a row. The offsets themselves are free to change — the panel is tuned by eye — as long as all three move with them.

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