Cookie settings

We use analytics cookies to improve the service. Learn more

ALPHANO Logo

TicTacToe

Top PlayerSubmissionsParticipants

Problem

Two players play a game of Tic-Tac-Toe on a 3×33 \times 3 board.

The board consists of 99 cells, ranging from row 11 and column 11 to row 33 and column 33. A cell at the xx-th row and yy-th column is denoted as (x,y)(x, y).

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 . 99 Entire board from (1,1)(1, 1) to (3,3)(3, 3)
First-player piece O 00 None
Second-player piece X 00 None

The game begins with the first player, and the two players take turns.

During their turn, a player selects an empty cell (x,y)(x, y) and places their piece.

Below is an example of the first player placing a piece at (1,3)(1, 3):

The game ends when any of the following conditions are met:

  • If 33 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 (x,y)(x, y).
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, y are integers.
  • my_time, opp_time, and time are 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

Limit

  • Time: In the first TURN command, my_time is 10,000ms10{,}000\mathrm{ms} for each player.
  • Memory: 1,024MB1{,}024\mathrm{MB}
  • Judge environment: HELP > Judge environment