Gomoku
Problem
Two players play a game of Omok on a board.
The board consists of cells, ranging from row and column to row and column . A cell at the -th row and -th column is denoted as .
Each cell can be in one of three states: an empty cell ., the first player's stone B, or the second player's stone W. Initially, the stones are arranged as follows:
| State | Count | Initial Placement |
|---|---|---|
Empty cell . |
Entire board from to | |
First-player stone B |
None | |
Second-player stone W |
None |
The game begins with the first player, and the two players take turns.
During their turn, a player selects an empty cell and places their stone.
Below is an example of the first player placing a stone at :

The game ends when any of the following conditions are met:
- If or more identical stones are placed consecutively in a horizontal, vertical, or diagonal direction, the player who placed those stones wins.
- If all cells on the board are filled but no player has met the winning condition, the game ends in a draw.
Please design an AI to become the ultimate winner of the board!
Input
The judge program communicates with the agent using single-line text commands as follows:
| Command | Judge → Agent (Input) | Agent → Judge (Output) | Time Limit (ms) | Description |
|---|---|---|---|---|
| READY | READY (FIRST or SECOND) |
OK |
3000 |
Informs whether you are the first or second player. |
| TURN | TURN my_time opp_time |
MOVE x y |
my_time |
Informs your remaining time and the opponent's remaining time. Output the chosen . |
| OPP | OPP x y time |
- | - | Informs the opponent's last move and the time they used. |
| FINISH | FINISH |
- | - | Signals the end of the game. The agent must terminate normally without further output. |
x,yare integers.my_time,opp_time, andtimeare integers representing time in milliseconds.- After every output, you must print a newline character and flush the buffer.
- Failure to output within the time limit results in a Time Limit Exceeded (
TLE) verdict. - Outputting an invalid format or an illegal move during a TURN command results in a Runtime Error (
RE) verdict.
Example
| First Player Input | First Player Output | Second Player Input | Second Player Output |
|---|---|---|---|
READY FIRST |
READY SECOND |
||
OK |
OK |
||
TURN 10000 10000 |
|||
MOVE 8 8 |
|||
OPP 8 8 50 |
|||
TURN 10000 9950 |
|||
MOVE 9 8 |
|||
OPP 9 8 20 |
|||
| ... | ... | ... | ... |
FINISH |
FINISH |
Sample Code
- C20 : sample.c
- CPP20 : sample.cpp
- PYTHON3, PYPY3 : sample.py
Limit
- Time: In the first TURN command,
my_timeis for each player. - Memory:
- Judge environment: HELP > Judge environment
