Problem
This game is a chess variant played on a board, where you place citizens and promote them to checkmate the opponent's king.
The board uses files a through e from left to right and ranks 1 through 5 from White's side to Black's side. A square is written as its file followed by its rank, such as a1 or c4. White's home rank is rank 1, and Black's home rank is rank 5.
The first player plays White and the second player plays Black. Initially, the white king is on c1 and the black king is on c5, and all other squares are empty. Starting with White, the two players act alternately.
Except for citizens, pieces follow the standard chess rules for movement, attacks, and captures. Castling and en passant are not allowed.
Citizens cannot move or attack. At the start of each turn, the level of every citizen owned by the current player increases by , and a level never exceeds .
On your turn, you perform one of the following three actions.
- Place a citizen: Place a level citizen on an empty square of your home rank.
- Promote a citizen: Turn one of your citizens into a regular piece that its current level allows.
- Move a piece: Move one of your pieces according to its movement rules. If an opponent's piece is on the destination square, it is captured.
A citizen can be promoted to a piece whose minimum level in the following table is at most the citizen's current level.
| Promotion piece | Minimum level required |
|---|---|
| Pawn | |
| Knight | |
| Bishop | |
| Rook | |
| Queen |
When a pawn reaches the opponent's last rank, it must be promoted to a knight, bishop, rook, or queen as part of the same action.
The following actions are invalid.
- Printing a string that does not match the output format, or coordinates outside the board
- Choosing a starting square that does not hold your own piece, or making a move that breaks the piece's movement rules
- Placing a citizen on a square outside your home rank or on a square that already has a piece
- Promoting a citizen whose level is too low, or choosing a piece that is not allowed
- Moving a pawn to the last rank without choosing a promotion piece, or choosing a piece that is not allowed
- Leaving your own king in check after the action
A player who makes an invalid action loses immediately, and that action is not applied to the board. A player also loses immediately if they fail to respond within the time limit or if an error occurs while their program is running.
Each player has a total of for the entire game. Response time spent on game setup and on all of your turns is cumulatively deducted, and the remaining time does not grow back on the next turn.
Each accepted action counts as ply. After applying an action, the game checks whether it has ended in the following order.
- If the next player has no legal action and their king is in check, it is checkmate.
- If the next player has no legal action but their king is not in check, it is stalemate and the game is a draw.
- Even if neither condition 1 nor condition 2 is met, the game is a draw once it reaches plies.
Design an AI that plans both when to promote citizens and how to move regular pieces, checkmates the opponent's king, and becomes the final winner!
Input
In the standard initial state, the white king is on c1, the black king is on c5, and all other squares are empty. Starting from this state, the player must track the current state by applying, in order, its own output actions and the opponent actions received via OPP.
The judge communicates with the players one line at a time as follows.
| Command | Judge→Player (input) | Player→Judge (output) | Time limit (ms) | Description |
|---|---|---|---|---|
| READY | READY role |
OK |
Current total remaining time | Uses role to tell the player whether they move first or second. |
| TURN | TURN remainingMs |
One line with a legal action | remainingMs |
Announces your turn and your current remaining total response time. |
| OPP | OPP action... |
- | - | Gives the accepted action the opponent just performed. |
| FINISH | FINISH |
- | - | Announces the end of the game. The program must exit normally without any further output. |
roleisFIRSTorSECOND.FIRSTis the first player, who plays White, andSECONDis the second player, who plays Black.remainingMsis an integer giving, in milliseconds, the total time the player has left before the current response. Its value is between and inclusive. When the remaining time reaches , the player loses by time limit exceeded without receiving another TURN.- The square coordinates
square,from, andtorange froma1toe5and match the regular expression[a-e][1-5]. - The piece name
pieceis one ofPAWN,KNIGHT,BISHOP,ROOK,QUEEN. - All commands and piece names use the uppercase spelling shown in the tables.
The actions you can output on TURN are as follows.
| Action | Output format | Meaning |
|---|---|---|
| Place a citizen | SPAWN square |
Places a level Citizen on square, an empty square of your home rank. |
| Promote a citizen | PROMOTE square piece |
Turns your Citizen on square into piece, which its current level must allow. |
| Move a piece | MOVE from to |
Moves your piece on from to to. |
| Pawn promotion move | MOVE from to piece |
Moves a Pawn to to on the last rank and promotes it to one of KNIGHT, BISHOP, ROOK, QUEEN. |
When the game starts, the judge sends READY to each player in turn and checks for OK. Once both players are ready, it sends the first TURN to the White player.
If your action is legal and the game continues, the judge first sends the same action to the opponent as OPP action... and then sends that opponent a TURN. The player must apply its own output action without any separate confirmation input.
If an accepted action results in checkmate or a draw, that action is not sent to the opponent as OPP, and FINISH is sent to both sides instead. Invalid output and illegal actions are not passed to the opponent either.
Each player has milliseconds for the entire game. Response time for READY and all of your TURN responses is cumulatively deducted from that same total, and it does not grow back on the next turn. One player's time usage does not affect the opponent's time.
Each line the player outputs is at most bytes, including the trailing LF. After every output, print a newline and then flush the buffer. Print debug messages only to standard error. Do not print anything when no response has been requested, and do not print anything other than the specified responses to standard output.
A player loses immediately if they fail to respond within the time limit, if their program exits before FINISH, if the output format is wrong, or if they output an action that is illegal under the game rules. A failed action is not applied to the game state and is not passed to the opponent.
Example
Communication in a match can proceed as follows. An empty cell means that the player has no input or output at that point, and time values are for illustration only.
| First player input | First player output | Second player input | Second player output |
|---|---|---|---|
READY FIRST |
OK |
||
READY SECOND |
OK |
||
TURN 5000 |
SPAWN e1 |
||
OPP SPAWN e1 |
|||
TURN 5000 |
SPAWN e5 |
||
OPP SPAWN e5 |
|||
TURN 4998 |
PROMOTE e1 PAWN |
||
OPP PROMOTE e1 PAWN |
|||
TURN 4997 |
PROMOTE e5 PAWN |
||
OPP PROMOTE e5 PAWN |
|||
TURN 4996 |
MOVE e1 e2 |
||
OPP MOVE e1 e2 |
|||
FINISH |
FINISH |
Both programs apply their own output actions and the opponent actions received via OPP to their own boards. If the last accepted action ended the match, that action is not passed to the opponent as OPP, and the next input is FINISH.
Sample code
Author
