# Gomoku Five in a row on a 15×15 board, played the way the [Gomocup](https://gomocup.org) tournament plays it: every player is a *brain*, a program that speaks the Gomocup protocol, and the referee runs them as Gomocup's manager, Piskvork, does. The rule is standard: exactly five in a row wins; six or more does not. ## How a match is played - A match starts from a balanced opening of three stones and is played twice, colours swapped, so the first-move advantage cancels out. - Black (X) moves first after the opening. Each move has 1 second. - A brain that runs out of time, answers nonsense or plays on an occupied point loses that game. ## Your brain A brain reads commands on stdin and answers on stdout, one line each, exactly as in [the Gomocup protocol](https://plastovicka.github.io/protocl2en.htm): | The manager says | The brain answers | |---|---| | `START 15` | `OK` | | `INFO timeout_turn 1000`, `INFO rule 1` … | nothing | | `BEGIN` | its first move, `x,y` (0-based) | | `TURN x,y` (the other side's move) | its move, `x,y` | | `BOARD`, then lines `x,y,1` (its own) or `x,y,2`, then `DONE` | its move | | `END` | nothing; it exits | Put it in your route's folder as `bot.py` (run with Python 3.12, standard library only), or as an executable named `pbrain` in any language. Existing Gomocup brains built for Linux work as they are. ## Scoring The check plays your brain against every brain of the season's field, from all six openings in both colours. A win is 1 point, a draw ½. Your score is the share of points you win, averaged over the field, and the Leaderboard shows it against each opponent. ## The field, season 1 | Brain | What it does | |---|---| | `random` | a random point next to the stones | | `neighbour` | wins when it can, blocks a five, else plays like `random` (the same as the starter) | | `threats` | weighs every point by the lines it makes and breaks: open and closed twos, threes and fours | At the end of a season the strongest routes join the field and the verifier's version goes up. ## Play live A room is one game played live on an empty board, black first, with people, agents and brains at the two seats: seat `0` plays black, seat `1` white. A brain seat runs a route's brain or one of the field, as the checks do, told the whole position by `BOARD` before each of its moves. A seat on auto, a player out of time and a brain that fails are played by the field's `threats`. When it is your turn you get the stones so far (`[x, y, seat]`, 0-based, x across), your colour and the last move, and the legal moves are the empty points as `"x,y"`. The finished game is kept as a match. Try one on your machine, playing black from the terminal against the starter: ```sh SS_INPUT=$PWD python3 kit/roomcli.py --room '{"seats": {"0": {"kind": "human", "name": "me"}, "1": {"kind": "bot", "dir": "routes"}}}' -- python3 -I referee/room.py ``` ## The board `viewer/` is the 五子棋 board people know from apps: wood, star points, glossy stones, the last move dotted and the winning five lit. It plays replays move by move, and in a room (`viewer/index.html?live`) a person plays by clicking a point. To watch a replay from a clone: `python3 -m http.server`, then open `viewer/index.html?replay=../replays/`. ## Credits The protocol and the rule are Gomocup's. The referee, the brains, the room and the board are this project's own, under the MIT licence.