The Goal

Claim more territory than your opponent across 2 games with colors and first move swapped. The higher combined territory score wins the match.

 Rules

Board and placement

  • Each game starts on an empty 16 by 16 board.
  • Black plays first. Black and White then alternate, placing 1 stone per turn.
  • A placement must be on an empty cell with no stone in any of its 8 neighboring cells, including diagonals. This applies to stones of either color.
  • Neighbors outside the board are ignored. On an empty board, every cell is legal.
  • Stones never move or disappear. Passing is not allowed.

A stone blocks its eight neighboring cells, including diagonals. Empty cells farther away remain legal.

Cell coordinates and action indices

Rows are numbered from 0 at the top to 15 at the bottom. Columns are numbered from 0 on the left to 15 on the right.

Every cell has an integer action index. Start at 0 in the top-left corner, count from left to right, then continue on the next row. The top row has indices 0 through 15; the next row starts at 16; the bottom-right cell is 255.

For a cell at row row and column column, its index is action = row * 16 + column. For example, row 2, column 3 has index 35.

A match contains two games

Each match consists of exactly 2 independent games with colors and first move swapped.

  • Game 1: player 0 is Black; player 1 is White.
  • Game 2: player 1 is Black; player 0 is White.
  • Both games start from an empty board and use the same rules.
  • The games advance in parallel. While both are active, each player acts on a different board.
  • Each input describes only the board on which you must act now. Check gameId and side every turn; keep any saved board history separate for each game.

When a game ends

  • A game ends immediately when no legal placement remains. Neither player receives an extra turn.
  • If one game ends first, play continues on the remaining board.
  • The match ends once both games have ended, unless a player forfeits earlier.

 Territory Scoring

When a game ends, score all 256 cells, including occupied cells and empty cells where placement is forbidden. Each cell is worth at most 1 point.

Distance layers

Measure the straight-line (Euclidean) distance from the cell being scored to each stone. Stones at the same distance form a distance layer.

  • dr is the difference between the row of the cell being scored and the row of a stone.
  • dc is the difference between the column of the cell being scored and the column of that stone.

You can compare squared distances exactly using dr * dr + dc * dc. This gives the same distance order without square roots.

Who receives the point?

  1. Inspect the distance layers from nearest to farthest.
  2. In the current layer, count the Black stones and the White stones.
  3. If one color has more stones, that color receives 1 point for the cell. Stop scoring this cell.
  4. If the counts are equal, ignore that layer and inspect the next one. Do not carry its counts forward.
  5. If every layer is tied, the cell is unclaimed and neither color receives a point.

An occupied cell belongs to its own stone's color, because that stone is at distance 0.

Example: the nearest layer contains 1 Black stone and 1 White stone. Skip that layer. If the next layer contains 2 Black stones and 1 White stone, Black receives 1 point.

For target cell X, squared distance 4 has one Black and one White stone and is skipped. Squared distance 8 has two Black stones and one White stone, so Black receives the point.

Combined match score

Each player's match score is the sum of their territory points from both games, following their own color on each board. Compare this total; individual game wins do not decide the match.

Example: player 0 scores 130 against 126 in game 1, then 120 against 136 in game 2. The combined scores are 250 against 262, so player 1 wins the match even though each player won one game.

Game 1: P0 is Black and scores 130, P1 is White and scores 126. Game 2: P1 is Black and scores 136, P0 is White and scores 120. P1 wins 262 to 250 on combined territory.

 Victory Conditions

  • Finish both games with a higher combined territory score than your opponent.
  • Or, your opponent forfeits the match and you do not forfeit on the same match turn.

 Defeat Conditions

  • Finish both games with a lower combined territory score than your opponent.
  • Or, forfeit by exceeding the response time limit, producing malformed output, or choosing an illegal action, while your opponent does not forfeit on the same match turn.

A forfeit ends the entire match, regardless of the territory already scored.

Draw Conditions

 Game Protocol

Input per game turn

Line 1: five space-separated integers, in this order: gameId side ply myScore opponentScore.

  • gameId: the game on which you must act, 1 or 2.
  • side: your color on this board, 1 for Black or 2 for White.
  • ply: the number of stones already placed on this board.
  • myScore: your combined territory score from completed games only.
  • opponentScore: your opponent's combined territory score from completed games only.

Both score fields are 0 until the first game ends. They do not include territory on an unfinished board.

Next 16 lines: the board rows, from top to bottom. Each row is a string of exactly 16 characters without spaces:

  • B: a Black stone.
  • W: a White stone.
  • .: an empty cell, which may or may not be a legal placement.

Next line: an integer legalActionCount, the number of legal placements available on this board for this turn.

Next legalActionCount lines: one integer action per line, identifying a legal placement using the cell numbering defined in Rules.

Output per game turn
Output one line containing a single integer action from the supplied list of legal actions.
Constraints
  • Each match has 2 players.
  • Each match contains 2 games.
  • Each board has 16 rows and 16 columns.
  • 1 ≤ gameId ≤ 2.
  • 1 ≤ side ≤ 2.
  • 1 ≤ legalActionCount ≤ 256 whenever input is sent.
  • 0 ≤ action ≤ 255.
  • A final territory score across both games is between 0 and 512.
  • Response time for your first decision of the match: 1000 milliseconds.
  • Response time for each later decision: 50 milliseconds, including your first decision on the other board.

Starter Bot: One-Ply Greedy (C++17)

To start playing, select C++ in the IDE, replace the editor contents with this complete program, and click Play my code.

The bot tries each supplied legal action, scores the resulting position using the territory rules, and chooses the largest difference between its own and its opponent's territory. Equal evaluations keep the first action in the supplied list.

This is an entry-level baseline. It looks only one move ahead and does not predict the opponent's reply. It is not guaranteed to beat the bosses. Territory during play is only a heuristic; the match is decided by the final combined score.

Each input contains the full board. This example rebuilds the position every turn and uses the supplied side, so it needs no persistent history for either game.

// Hexadeca starter bot: choose the best territory difference after one move. #include <array> #include <iostream> #include <string> #include <vector> using namespace std; constexpr int SIZE = 16; constexpr int MAX_DISTANCE_SQUARED = 2 * (SIZE - 1) * (SIZE - 1); struct Stone { int row, column, side; }; int territoryDifference(const vector<Stone>& stones, int mySide) { int result = 0; for (int row = 0; row < SIZE; ++row) { for (int column = 0; column < SIZE; ++column) { // Each entry counts only ONE squared-distance layer. array<int, MAX_DISTANCE_SQUARED + 1> balance{}; for (const Stone& stone : stones) { int dr = row - stone.row; int dc = column - stone.column; balance[dr * dr + dc * dc] += (stone.side == mySide ? 1 : -1); } for (int difference : balance) { // Tied layers are skipped; their counts are not carried forward. if (difference == 0) continue; result += (difference > 0 ? 1 : -1); break; } // If every layer is tied, this cell adds no points. } } return result; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int gameId, side, ply, myScore, opponentScore; while (cin >> gameId >> side >> ply >> myScore >> opponentScore) { // The full board is provided every turn, so no saved history is needed. // This also handles the two boards and changing colors automatically. vector<Stone> stones; for (int row = 0; row < SIZE; ++row) { string line; cin >> line; for (int column = 0; column < SIZE; ++column) { if (line[column] == 'B') stones.push_back({row, column, 1}); if (line[column] == 'W') stones.push_back({row, column, 2}); } } int legalActionCount; cin >> legalActionCount; vector<int> actions(legalActionCount); for (int& action : actions) cin >> action; int bestAction = actions.front(); int bestValue = -SIZE * SIZE - 1; for (int action : actions) { stones.push_back({action / SIZE, action % SIZE, side}); int value = territoryDifference(stones, side); stones.pop_back(); if (value > bestValue) { bestValue = value; bestAction = action; } } cout << bestAction << endl; // endl flushes the decision to the referee. } }

Credits and Referee Source

Hexadeca CodinGame contribution by Srot, built with the open-source CodinGame Game Engine.

Download the Java referee source. The placement and territory rules are implemented in HexadecaRules.java; the two-game match is managed by HexadecaMatch.java and Referee.java.

The contribution page contains community feedback and the latest project source download.