#P6050. Shik’s Grid Game Simulation
Shik’s Grid Game Simulation
Shik’s Grid Game Simulation
Shik has invented a game played on an N × N grid (where N is even). The grid coordinates are defined so that the top‐left cell is (1,1) and the bottom‐right cell is (N,N). The initial configuration is as follows:
- All cells in the leftmost column contain a red piece, and all cells in the rightmost column contain a blue piece.
- The top row is split into two halves. The left half cells (first N/2 cells) also contain red pieces, and the right half cells (last N/2 cells) contain blue pieces.
- The bottom row is arranged similarly: the left half cells contain red pieces and the right half cells contain blue pieces.
The game is played by two players, red and blue. Red always makes the first move. In each move a player can select one of his own pieces and move it one step in one of the four directions (up, down, left, right) provided the target cell is empty.
After each move, the current player may perform a capture in the row or column that contains the destination cell. (For the purpose of this problem, assume N = 4 so that the capture condition is as follows.) In any row or column, if:
- The total number of pieces on that line is exactly N - 1 (i.e. 3 pieces).
- Among these, exactly 2 pieces belong to the moving player and 1 piece belongs to the opponent.
- The cells that contain these pieces are consecutive (i.e. if the indices are sorted, then max_index - min_index = number_of_pieces - 1).
- The configuration was created by the player’s own move (i.e. the moved piece is part of that line).
If all conditions are met for that row or column, then all opponent pieces in that line are removed (i.e. captured).
The game terminates if at any time:
- One side has exactly N/2 pieces remaining (in which case the other side wins), or
- The player whose turn it is has no legal moves (i.e. none of his pieces can move to an adjacent empty cell). In this case the other side wins.
If the game does not end before all moves are processed, output the final board configuration.
In the output, print the board configuration as N lines each containing N characters. Use R
for a red piece, B
for a blue piece, and .
for an empty cell.
Note: Coordinates in the input are 1-indexed.
inputFormat
The first line contains two integers N and M (with N = 4 for this problem and N even), where N is the grid size and M is the number of moves.
Each of the following M lines contains four integers r1 c1 r2 c2
, representing a move from cell (r1, c1) to an adjacent cell (r2, c2). It is guaranteed that all moves are valid and follow the rules.
outputFormat
Output the final board configuration. Print N lines, each line containing N characters. Use R
to represent a red piece, B
to represent a blue piece, and .
to represent an empty cell.
sample
4 3
1 2 2 2
4 3 3 3
2 2 2 3
R.BB
R.RB
R.BB
RR.B
</p>