← 返回 cisco 的题目列表Chessboard Piece Placement with Opposite Color Constraints
类型:online_judge
cisco
Object-Oriented Design: Design a chessboard program where n white and n black pieces are placed at the start, following specific rules. The chessboard is of size 8x8, and the rules are as follows:
Pieces can only be placed on empty squares.
At the initial state, the board contains n white and n black pieces, placed randomly.
Black and white pieces cannot be placed on the same row, column, or diagonal as other pieces of the opposite color.
Implement the following functions:
place_piece(x: int, y: int, color: str) -> bool: Attempt to place a piece of the specified color at coordinates (x, y), returning if successful.
remove_piece(x: int, y: int): Remove the piece at coordinates (x, y).
print_board(): Print the current state of the board.
Input and Output Requirements:
You will be provided with a series of piece placement and removal operations.
After each operation, output the current board state.
Example
Input
8
0 0 B
2 2 W
4 5 W
7 7 B
print