← 返回 sofi 的题目列表Tic Tac Toe Implementation
类型:online_judge
Design and implement a simple Tic Tac Toe game. The rules are as follows:
The game board is a 3x3 grid. One player is X, the other player is O.
Players take turns placing their marks on empty squares.
A player wins if they occupy all positions in a row, column, or diagonal with their marks.
The game is a draw if all squares are filled and no player wins.
Please write a class to support the following operation:
move(row: int, col: int, player: int) -> int:
The player is either 1 (representing player X) or 2 (representing player O).
Place a mark for the player on the specified row and col position.
Return the player's number if they win after this move. Return 0 if the game is still ongoing.
Throw an error if the input is invalid (e.g., the position is already occupied).
Provide sufficient test cases to validate your implementation.
Example
Input
game.move(0, 0, 1)
game.move(1, 1, 2)
game.move(0, 1, 1)
game.move(0, 2, 1)