Problem
Two players take turns placing stones on an board and flipping the opponent's stones.
The board consists of cells arranged in rows and columns. Rows are numbered from to from top to bottom, and columns are numbered from to from left to right. The cell in row and column is denoted .
Each cell is in one of three states: empty ., black stone B, or white stone W. At the start of the game, white stones are placed on and and black stones on and , and all other cells are empty.
The game starts with the first player, who plays black, and the two players take turns alternately. On your turn, you choose one empty cell and place a stone of your color there.
The cell where you place a stone must satisfy the following conditions.
- In at least one of the eight horizontal, vertical, and diagonal directions from that cell, there must be one or more consecutive opponent stones.
- The cell right after those consecutive opponent stones must hold one of your own stones. If an empty cell or one of your own stones comes in between, opponent stones beyond it are not included.
When a player places a stone, the following steps happen in order.
- The current player's stone is placed on the chosen empty cell.
- All eight directions from the newly placed stone are checked to find every opponent stone sandwiched in a direction that satisfies the conditions above.
- All of those stones are flipped to the current player's color. If the conditions hold in several directions, the stones in all of those directions are flipped.
Even if flipping causes opponent stones to become sandwiched in another direction, they are not flipped further. Only the directions extending directly from the newly placed stone are checked.
For example, if black places a stone on on the first turn, the white stone on is flipped to black. The cells black can choose at the start are , , , and .
If there is no cell where you can place a stone on your turn, you pass. If there is at least one cell where you can place a stone, you cannot pass. You cannot choose a cell that already has a stone or a cell where no opponent stone would be flipped.
If neither player can place a stone, the game ends even if empty cells remain on the board.
When the game ends, the player with more stones of their color wins. If both players have the same number of stones, the game is a draw.
Design an AI that flips the opponent's stones, holds more stones, and becomes the final winner!
Input
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 (FIRST | SECOND)` | OK |
That player's remaining total time |
| TURN | TURN turn board |
MOVE r c or PASS |
That player's remaining total time | Gives the current turn number and the board. Output the coordinates where you place a stone, or PASS if there is no cell where you can place one. |
turn,r, andcare integers.turnis a turn number that counts the actions of both players, starting from . It increases by even when a player passes.boardis a string of length . Starting from row , column , each row is listed from left to right, and the rows are joined from the top row to the bottom row.- Each character of
boardis one of empty., black stoneB, or white stoneW. The state of is the -th character from the start of the string. randcare between and inclusive and denote the row counted from the top and the column counted from the left, respectively.- On each of your turns, the judge sends the entire current board. The opponent's previous action is already reflected in this board, and no input is given during the opponent's turn.
- Each player has a total of for the entire game, from which the response times for READY and all of your TURN responses are deducted. Time spent waiting for the opponent's response is not deducted.
- Your remaining time is not given as a separate value in the input. A new time limit is not granted each turn.
- A separate limit also applies to the CPU time used by the whole program.
- After every output, print a newline and then flush the buffer. Respond to each request with exactly one line made of the specified tokens.
- If you fail to respond within your remaining total time or your program terminates abnormally, you lose immediately.
- If you print a string that does not match the output format or illegal coordinates, you lose immediately. You also lose immediately if you print
PASSwhile there is a cell where you can place a stone. - When the game ends, the judge terminates the player's program without sending any further commands.
Example
The following is an example of communication between the two players and the judge, starting from the initial board.
| First player input | First player output | Second player input | Second player output |
|---|---|---|---|
READY FIRST |
|||
OK |
|||
READY SECOND |
|||
OK |
|||
TURN 1 ...........................WB......BW........................... |
|||
MOVE 3 4 |
|||
TURN 2 ...................B.......BB......BW........................... |
|||
MOVE 3 3 |
|||
TURN 3 ..................WB.......WB......BW........................... |
|||
MOVE 3 2 |
|||
When the first player places a stone on , the white stone on is flipped to black. Next, when the second player places a stone on , the black stone on is flipped to white. Then, when the first player places a stone on , the white stone on is flipped to black.
If there is no cell where you can place a stone on your turn, print PASS instead of MOVE r c. Once the game ends, no more input is given.
Sample code
Author
