Loading workspace…

Tic-tac-toe

Languages

Tic-tac-toe is a game for two players who take turns marking spaces in a three-by-three grid with X or O. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner.

Source: Wikipedia

Build a tic-tac-toe game that is playable by two players.

Tic-tac-toe Example

Requirements

  • Players can take turns to place an X or an O on the board.
  • Player X takes the first turn, and turns alternate after each valid move.
  • A player wins if three of their marks are in a horizontal, vertical, or diagonal row.
  • Display the current game status at the top: whose turn it is, winner (if any), or draw.
  • After a win or draw, no further marks can be placed until the game is reset.
  • Use buttons for the cells. Each cell's accessible name should identify its one-based position and the mark it will place or currently contains, and status changes should be announced politely.
  • Add a "Reset" button to allow the game to be restarted at any time.

If you aren't familiar with the game, try out playing tic-tac-toe on Google.

Changelog

  1. Game state and accessible cell names

    X moves first, turns alternate after valid moves, and the board stops accepting moves when the game ends. The checks cover names that announce both the cell position and its pending or current mark.