Description
Design a Tic-tac-toe game that is played between two players on a n x n grid.
You may assume the following rules:
- A move is guaranteed to be valid and is placed on an empty block.
- Once a winning condition is reached, no more moves is allowed.
- A player who succeeds in placing n of their marks in a horizontal, vertical, or diagonal row wins the game.
Example:
1 | Given n = 3, assume that player 1 is "X" and player 2 is "O" in the board. |
Follow up:
Could you do better than O(n2) per move()
operation?
Solution
1 | class TicTacToe { |