Bacteria War
Problem
[ALPHANO] Bacterial War Rule Explanation (Youtube)
Two types of bacteria (O and X) compete for dominance on a culture plate.
The culture plate consists of cells arranged in rows and columns. Rows are numbered to from top to bottom, and columns are numbered to from left to right. A cell at the -th row and -th column is denoted as .

Each cell can be in one of three states: empty ., first-player bacterium O, or second-player bacterium X. Initially, cells and contain the first-player bacterium O, while and contain the second-player bacterium X. The remaining 45 cells are empty ..
The battle begins with the first player O, and players O and X take turns. During their turn, a player can spread their bacteria by selecting a starting cell where their bacterium is located and an empty destination cell .
- The movement distance must be either or .
- If the movement distance is , it is called Division. In a Division move, the bacterium at the starting cell remains, and a new bacterium of the same type is created at the destination cell .
- If the movement distance is , it is called a Leap. In a Leap move, the bacterium at the starting cell disappears (becoming an empty cell
.), and a new bacterium is created at the destination cell . - Immediately after a Division or Leap action, Infection occurs. Infection means that any opponent's bacteria in the adjacent cells (horizontal, vertical, and diagonal) around the destination cell are converted to the current player's bacterium type.
- If there are no legal Division or Leap moves available, the player must select
PASS. In this case, the turn passes without any change to the culture plate.
In summary, each player chooses either Division or Leap if a move is possible, followed by Infection. If no moves are possible, they must PASS.
Below is an example of the first player performing a Division from to :

Below is an example of the second player performing a Leap from to :

Finally, here is an example where the first player must select PASS:

The battle ends when any of the following conditions are met:
- One type of bacteria completely disappears from the board.
- There are no empty cells left on the board.
- Both players have performed actions each (total of turns).
At the end of the game, the player occupying more cells wins. If both players occupy the same number of cells, it is a draw.
Please design an AI to become the ultimate winner of the culture plate!
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 | SECOND) |
OK |
3000 |
Informs whether you are the first or second player. |
| TURN | TURN my_time opp_time |
MOVE x1 y1 x2 y2 |
my_time |
Informs your remaining time and the opponent's remaining time. Output the chosen and . For PASS, output MOVE -1 -1 -1 -1. |
| **OPP | OPP x1 y1 x2 y2 time |
- | - | Informs the opponent's last move and the time they used. If the opponent chose PASS, OPP -1 -1 -1 -1 time is given. |
| FINISH | FINISH |
- | - | Signals the end of the game. The agent must terminate normally without further output. |
x1,y1,x2,y2are 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 2 2 |
|||
OPP 1 1 2 2 50 |
|||
TURN 10000 9950 |
|||
MOVE 7 7 6 6 |
|||
OPP 7 7 6 6 20 |
|||
TURN 9950 9980 |
|||
MOVE -1 -1 -1 -1 |
|||
FINISH |
FINISH |
Sample Code
- C20: sample.c
- CPP20: sample.cpp
- PYTHON3, PYPY3: sample.py
Limit
- Time: For the first TURN command given to each agent,
my_timeis ms. - Memory: 1024MB
- Judging Environment: HELP > Judging Environment
