#K3811. Chessboard Operations Simulator
Chessboard Operations Simulator
Chessboard Operations Simulator
Implement a class Chessboard
to manage an 8x8 chessboard. The board is initially empty, represented by the character .
in every cell. You must support the following operations:
- place x y S: Place the piece (character
S
) at coordinates(x, y)
. - remove x y: Remove any piece at position
(x, y)
(i.e. set it to.
). - move x1 y1 x2 y2: Move a piece from position
(x1, y1)
to(x2, y2)
. After moving, the original cell becomes empty. - piece x y: Output the piece at position
(x, y)
. If the cell is empty, outputempty
. - display: Print the entire board. Each of the 8 rows should be printed on a new line, with no spaces between characters.
All coordinates are 0-indexed with 0 ≤ x, y ≤ 7.
Input Format: The first line of input contains an integer N representing the number of operations. The following N lines each contain one of the commands described above.
Output Format: For each command that requires output (piece
and display
), output the result immediately. For a piece
command, output a single line with the result. For a display
command, output 8 lines representing the board state.
Note: The operations will be processed in the order they appear. Make sure your solution reads input from stdin
and writes output to stdout
.
Mathematically, if you denote the board as a matrix B with indices from 0 to 7, then for a placement operation:
$$B_{x,y} = S,$$and for removal:
$$B_{x,y} = \text{'.'}.$$inputFormat
The first line of input contains an integer N (the number of operations). Each of the next N lines contains one command. The commands are:
- place x y S : Place a piece denoted by character
S
at coordinates(x, y)
. - remove x y : Remove the piece at coordinates
(x, y)
. - move x1 y1 x2 y2 : Move the piece from
(x1, y1)
to(x2, y2)
. - piece x y : Output the contents at
(x, y)
. - display : Print the full chessboard (8 lines, each with 8 characters).
outputFormat
For each piece
command, output a single line containing the piece at that cell or empty
if no piece is present. For each display
command, print 8 lines representing the chessboard where each line is a row of the board.
3
place 0 1 K
piece 0 1
display
K
.K......
........
........
........
........
........
........
........
</p>