Dynamic Tic Tac Toe

MediumTic Tac ToeReact30 mins

by Pratik Rai

Read the full write-up

Build tic tac toe on a board whose size the player chooses — 3x3, 4x4 or 5x5. A line of n marks in a row wins.

winningLines(n) is given: it returns every winning line as an array of cell indices.

Requirements

  1. X moves first, and turns alternate.

  2. Clicking a filled cell does nothing, and no move is possible once the game is over.

  3. A full line of the same mark — row, column or either diagonal — wins, on any board size.

  4. The status line shows whose turn it is, who won, or that it is a draw.

  5. The winning cells are highlighted with the .cell-winning class.

  6. Changing the board size or pressing Reset starts a fresh game with X to move.

Notes

  • A draw is a full board with no winner.

  • Cell indices are flat: row r, column c is index r * size + c.

  • No AI opponent — two players share the board.

Hints

Loading editor…