Skip to content

COMP30024 · Artificial Intelligence · University of Melbourne

Cachex
Arena

In 2022 we built a game-playing agent for Cachex, a Hex-like race to connect opposite edges of a hexagonal board, with captures and a first-move steal. Here it is again, ported line by line from Python to run in your browser.

New here? Take the guided tour · three short walkthroughs
A real game: the ported agent playing itself on 7 × 7. Red wins in 35 turns.

The game

Three rules, a lot of tension

Two players take turns placing a tile on any empty hex. Whoever links their two edges first wins.

Red's chain runs from row 0 to row 4.

Connect your edges

Red links the top and bottom edges; Blue links the left and right. A chain of touching tiles is all it takes.

Before
After Blue plays
Blue plays (2, 1) and captures Red's (1, 1) and (2, 0).

Capture with a diamond

Place a tile that closes a diamond around exactly two enemy tiles, with your own tile opposite, and both enemy tiles are removed.

Red's opening at (1, 3) becomes Blue's (3, 1).

Steal the opening

Red moves first, so Blue may answer by stealing: Red's tile is mirrored across the long diagonal and becomes Blue's.

The coursework

What we were asked, and what we built

The project came in two parts. We have paraphrased the brief here; the original specification is not reproduced.

Part A · Search

The task: given a board with some occupied cells, find a shortest chain of empty cells from a start to a goal using A* with an admissible heuristic, and print its length and cells.

What we built: a CachexBoard of HexNodes with a priority-queue A* over the six hex neighbours, Minkowski heuristics (Manhattan or Euclidean), and an optional colour that blocks the search. A notebook experiment compared the heuristics on hundreds of random boards.

Open the A* Lab

Part B · Game-playing agent

The task: write a player the subject's referee could run against random, greedy and search-based opponents, within time and memory limits.

  • Minimax with alpha-beta pruning, Red maximising and Blue minimising.
  • Dynamic depth: depth 1 while at least 15% of cells are empty, then 2, 3 and 4 below 15%, 10% and 5%.
  • Opening book for the first two turns, and an instant-win check before any search.
Play against it

The evaluation function

Six hand-tuned features from weights.json, scored from Red's point of view (Red's count adds, Blue's subtracts).

  • Empty hexes+0.5

    Number of empty cells left on the board (shared, not per colour).

  • Triangle formations+3

    Tokens that form a solid triangle with two adjacent friendly neighbours.

  • Token count+8

    Tokens of each colour currently on the board.

  • Positional value+2

    Sum of cell scores: the rim scores higher than the centre.

  • Capturable diamonds−4

    Tokens sitting in a half-built diamond the opponent could complete.

  • Weak formations−3

    Tokens with an exposed gap that invites an attack.

Key results

From the original code

The agent and search results come from running the original Python, unchanged, with the subject's referee. The port is then checked against those same runs.

90%

wins against the random agent (144 of 160 games, both colours, boards 4 × 4 to 7 × 7; Wilson 95% CI 84.4% to 93.8%)

8 & 13

cells in the A* paths for the two sample inputs, matching the recorded outputs

Exact

parity: the TypeScript port reproduces the original paths, node counts, evaluations and moves

Agent _4399 vs the random baseline

20 seeded games per row, generated by scripts/benchmark_agent.py. Wilson 95% intervals; with 20 games a row each one is wide, so the pooled rate is the better summary.

BoardAgentWin rate (95% CI)W–LTurns
4 × 4 red85%[64, 95]17–314.2
4 × 4 blue75%[53, 89]15–513.8
5 × 5 red90%[70, 97]18–220.5
5 × 5 blue95%[76, 99]19–120.1
6 × 6 red90%[70, 97]18–229.6
6 × 6 blue90%[70, 97]18–232.2
7 × 7 red100%[84, 100]20–044.3
7 × 7 blue95%[76, 99]19–143.5

Measured, not claimed

How good is it, really?

The revival adds a seeded tournament harness, a paired A* study and an optional LLM evaluation, each reported with sample sizes and confidence intervals, plus the decisions and weaknesses behind them.

About this project

Credits and stack

COMP30024 Artificial Intelligence, University of Melbourne, Semester 1, 2022. Team _4399.

Team

Team _4399, a two-person project. Both members are credited as authors in the original source.

Original vs revived stack

2022
Python 3.6, NumPy, SciPy, Jupyter, the subject's referee
Now
Next.js 16, React 19, TypeScript, Tailwind CSS v4, shadcn/ui, Web Workers, Vitest

Parity fixtures are produced by running the original code with uv.

Source and integrity

The original submission is preserved unchanged in the repository's coursework/ folder for reference. If you are taking COMP30024, please respect academic integrity and do not copy it.