TicTacToe
Problem
Two players play a game of Tic-Tac-Toe 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 piece O, or the second player's piece X. Initially, the pieces are arranged as follows:
| State | Count | Initial Placement |
|---|---|---|
Empty cell . |
Entire board from to | |
First-player piece O |
None | |
Second-player piece X |
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 piece.
Below is an example of the first player placing a piece at :

The game ends when any of the following conditions are met:
- If identical pieces are placed consecutively in a horizontal, vertical, or diagonal direction, the player who placed those pieces 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 1 1 |
|||
OPP 1 1 50 |
|||
TURN 10000 9950 |
|||
MOVE 2 1 |
|||
OPP 2 1 20 |
|||
TURN 9950 9980 |
|||
MOVE 2 2 |
|||
OPP 2 2 50 |
|||
TURN 9980 9900 |
|||
MOVE 3 3 |
|||
OPP 3 3 20 |
|||
TURN 9900 9960 |
|||
MOVE 1 2 |
|||
OPP 1 2 50 |
|||
TURN 9960 9850 |
|||
MOVE 3 2 |
|||
OPP 3 2 20 |
|||
TURN 9850 9940 |
|||
MOVE 1 3 |
|||
FINISH |
FINISH |
The status of the board since the last MOVE 1 3 is the same as the figure in the statement.
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
