Domineering
Problem
Two players play the game of Domineering on an board.
1. Board and Components
The board consists of cells arranged from row , column to row , column . A cell at the -th row and -th column is denoted as . Initially, all cells on the board are empty, and each cell contains a single integer uniformly distributed between and , inclusive.
Below is an example of the initial board.

Initially, the first player starts the game with points, and the second player starts with points.
2. Gameplay
The game begins with the first player, and the two players take turns alternately.
During their turn, the first player can place a domino covering two horizontally adjacent empty cells, or select PASS. When placing a domino, the player must simultaneously cover the empty cells and on the board, and earns points equal to the sum of the integers written on the two cells.
Below is an example of the first player placing a domino covering and .

During their turn, the second player can place a domino covering two vertically adjacent empty cells, or select PASS. When placing a domino, the player must simultaneously cover the empty cells and on the board, and earns points equal to the sum of the integers written on the two cells.
Below is an example of the second player placing a domino covering and .

3. Game End
The game ends when both players select PASS consecutively, or when there are no valid positions left for either player to place a domino.
At the end of the game, the player with the higher score wins.
Please design an AI to become the ultimate winner of the board!
Input
Before the judge program and the agent begin communicating, the following input is provided over lines.
- On the -th line , the integers representing the numbers written on each cell of the board are given, separated by spaces.
Afterward, 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 cell to place the domino this turn. For PASS, output MOVE -1 -1. |
| OPP | OPP x y time |
- | - | Informs the opponent's last move and the time they used. If the opponent chose PASS, OPP -1 -1 time is given. |
| FINISH | FINISH |
- | - | Signals the end of the game. The agent must terminate normally without further output. |
- In the
MOVEandOPPcommands,xandyare integers. Ifxandyare not both-1, represents the coordinates of the cell with the smaller row and column numbers among the two cells covered by the placed domino. 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 |
|---|---|---|---|
0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 |
||
3 3 0 0 0 0 0 0 |
3 3 0 0 0 0 0 0 |
||
0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 |
||
0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 |
||
0 0 0 0 0 0 1 0 |
0 0 0 0 0 0 1 0 |
||
0 0 0 0 0 0 2 0 |
0 0 0 0 0 0 2 0 |
||
0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 |
||
0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 |
||
READY FIRST |
READY SECOND |
||
OK |
OK |
||
TURN 10000 10000 |
|||
MOVE 2 1 |
|||
OPP 2 1 50 |
|||
TURN 10000 9950 |
|||
MOVE 5 7 |
|||
OPP 5 7 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
