Problem
Build a Tic-Tac-Toe game with alternating turns and win detection. Then generalize to an N x N board with a configurable win length K.
Requirements
- 2 players alternate (X and O); clicking an empty cell places the current mark.
- Detect a win (row, column, or diagonal) and a draw; block further moves after game over.
- (N x N variant) Win requires K consecutive marks in any direction; allow configurable N and K.
- (Bonus) Reset button, highlight the winning line.
Hints / Approach
- 3x3: check 8 fixed lines after each move.
- N x N: after placing at
(r, c), check the 4 directions (horizontal, vertical, two diagonals) by counting consecutive same marks both ways from the last move — O(K) per move instead of scanning the whole board. - Keep board as a 2D array (or flat array). Track
currentPlayer,winner, andmovesCountfor draw detection.