Problem
Hanpang is a single-player game on a board in which you clear same-colored tiles all at once to earn a high score.
1. Board and Tiles
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 either empty or holds a tile of one of three colors. The color of each newly created tile is chosen from the three colors independently and with equal probability.
At the start of the game the board is empty, and one row of new tiles is added at the bottom.
2. Gameplay
In each turn, you select one non-empty cell . The selected tile and all same-colored tiles connected to it up, down, left, and right are removed. Tiles that touch only diagonally are not connected, and you may select a tile even if it is the only tile in its connected group.
Removing tiles at once earns points. After the removal, the remaining tiles in each column fall down so that no empty cells are left between them.
Then a row of new tiles is added at the bottom of the board, and the existing board shifts up by one row. This whole process makes up one turn.
3. Game End and Scoring
The game ends when any of the following conditions is met.
- Adding a new row pushes a tile that was in the top row off the board
- turns have been played
Points earned by the last action that ended the game also count toward the final score. The final score is the sum of all points earned until the game ends.
Design an AI that builds large connected components and earns a high score while new rows keep being added!
Input
The judge communicates with the player one line at a time as follows.
| Command | Judge→Player (input) | Player→Judge (output) | Time limit (ms) | Description |
|---|---|---|---|---|
| START | START |
READY |
Remaining total time | Announces the start of the game. Time spent on the response is deducted from the player's total time. |
| TURN | TURN remaining_ms new_row |
PANG row col |
remaining_ms |
Gives the remaining time and the new row to be added. After the new row is added at the bottom of the board, output the coordinates of the tile to remove. |
remaining_ms,row, andcolare integers.remaining_msis the player's remaining time in milliseconds.new_rowis a string of length , and each character is one of1,2,3, indicating a tile color. Thenew_rowgiven in the first TURN is also added as the bottom row of the board.rowis between and inclusive andcolis between and inclusive. They denote the row counted from the top and the column counted from the left, respectively.- The cell selected with
PANG row colmust contain a tile. A tile whose connected component has size can also be selected. - The player may use a total of across the START response and all TURN responses.
- After every output, print a newline and then flush the buffer.
- If you fail to respond within the remaining time, the game ends and the last confirmed score is used as the final score.
- If you print a string that does not match the output format or invalid coordinates, the game also ends, and the score confirmed just before that action is used as the final score.
- 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 player and the judge. Time values are for illustration only.
| Judge→Player input | Player→Judge output |
|---|---|
START |
READY |
TURN 5000 32131311 |
PANG 15 7 |
TURN 4999 11223312 |
PANG 15 7 |
Sample code
Author
