iago

Reversi variant built with Racket

View on GitHub

Iago

Reversi variant in Racket, with a dark interface and a computer opponent. It runs unchanged on macOS, Windows and Linux.

Iago is a port of othello.red, the same game written in Red.

Iago in the middle of a game: white and purple stones on a dark board

Running

Install Racket: the full distribution from download.racket-lang.org, not “Minimal Racket”. Iago was written and tested with version 9.3. Then:

racket main.rkt

Nothing else needs installing: the game uses only libraries that come with Racket.

Playing

White moves first. Click an empty square to place a stone; clicks on squares that would not flip anything are ignored. If a player has no legal move, the game says so and the turn passes back. The game ends when neither side can move.

The buttons along the bottom:

The window can be resized, and the board scales with it.

The computer player

The computer searches with negamax and alpha-beta pruning, deepening one ply at a time until its time budget runs out, then plays the best move from the last depth it finished. It judges positions with a table of square weights that favours corners and edges and avoids the squares next to corners. For the last twelve empty squares it counts stones instead.

The timings are constants in the source:

Constant File Default Meaning
THINK-MS computer.rkt 1000 Search time per computer move, in milliseconds. Raise it for a stronger, slower opponent.
MOVE-DELAY-MS game.rkt 800 Pause before each computer move, so you can follow the game.
PASS-DELAY-MS game.rkt 2000 How long a forced-pass notice stays on screen.

A standalone program

To make a program that runs without Racket installed (tried on macOS and Fedora 45 so far):

raco exe --gui -o Iago main.rkt
raco distribute dist Iago.app      # macOS; on Windows use Iago.exe, on Linux Iago

The dist folder can then be copied to another machine with the same operating system. raco exe builds for the system it runs on, so each of the three has to be built on that system.

How it is built

File What it holds
rules.rkt The board (a vector of 64 cells), and which stones a move flips.
search.rkt The computer player.
game.rkt The turn flow: whose move it is, forced passes, the end of the game, who plays each side. It has no window and is told the time, so it can be tested directly.
view.rkt Painting and hit-testing. The whole window, buttons included, is drawn onto one drawing context, so it looks the same on every system.
computer.rkt The computer’s turn: starting a search away from the window’s thread and playing its move when it comes back, unless the game has moved on meanwhile.
main.rkt The window: one canvas and a timer.

Run the tests with:

raco test .

Differences from the Red version