NxN tic-tac-toe variant with configurable win length and undo
A puzzle app wants one board that covers a family of games: 3×3 with three in a row is classic tic-tac-toe, 5×5 with four in a row is a quick lunch-break game, and 7×7 with five in a row is a mini Gomoku. Build a two-player game where players pick the board size N and the win length K, take turns placing marks, and can undo moves, including the winning one.
The starter code includes the settings:
const SIZE_OPTIONS = [3, 4, 5, 6, 7];
const MIN_WIN_LENGTH = 3;
const DEFAULT_SIZE = 5;
const DEFAULT_WIN_LENGTH = 4;
<select>s.
SIZE_OPTIONS (option values "3" to "7"). Default: 5.MIN_WIN_LENGTH up to the current board size. Default: 4.N × N squares rendered row by row. Each square is a <button> that shows its mark (X, O, or nothing) and has an aria-label of the form Row R, column C: Mark, where R and C start at 1 and Mark is X, O, or Empty.K or more of their marks in a row horizontally, vertically, or along either diagonal. Any line on the board counts, not only the main diagonals. After a win, clicks on squares do nothing.Next Player: X / Next Player: O during the game, Winner: X / Winner: O after a win, and Draw when the board is full with no winner.Default: 5 x 5, four in a row 25 squares, Next Player: X
X Row 1 col 1, O Row 2 col 1, X Row 1 col 2, O Row 2 col 2,
X Row 1 col 3, O Row 2 col 3 three in a row is not enough: Next Player: X
X Row 1 col 4 Winner: X
Undo Row 1 col 4 is Empty again, Next Player: X
O already has Row 2 col 5, Row 4 col 3 and Row 5 col 2.
O plays Row 3 col 4 the move completes the diagonal from the middle: Winner: O
Win length 4, change Board size to 3 9 empty squares, Win length becomes 3, Next Player: X
The tests click your squares and buttons, change the selects, and read the screen like a player would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
N × N elements whose aria-label reads Row R, column C: Mark, in row order, and the Mark part is correct after every action.value and options, and change them by setting value and firing input and change.Next Player: X/O, Winner: X/O, or Draw.Capitalization and extra spacing don’t matter.