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.

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.
- Windows: if
racketis not on yourPATH, run"C:\Program Files\Racket\Racket.exe" main.rkt, or openmain.rktin DrRacket and press Run. - Linux: the window needs a desktop session with GTK 3. If you install Racket from your distribution’s packages rather than from the download page, make sure the GUI libraries come with it.
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:
- White: Human / Computer and Purple: Human / Computer switch who controls each side. Any combination works, including computer against computer, and you can switch in the middle of a game.
- New Game resets the board at any time.
- Quit exits, as does closing the window.
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
- Purple instead of red, and the stones are shaded to look three-dimensional, lit from the upper left with a soft shadow, where the Red version draws flat circles.
- The window stays responsive while the computer thinks, and it can be resized.
- The computer is stronger at the same time budget, because compiled Racket code gets through more positions in a second than Red’s interpreter does. From the opening position it finishes a 13-ply search in one second on the Mac it was written on.
- A game that ends on a full board is scored the same way as one that ends because neither side can move. The Red search scores a full board lower, so it can prefer a narrow win that ends early to a wider win that fills the board.