Skip to content
md ~/projects/tic-tac-toe
Project archive

2026Live

Tic-Tac-Toe

  • JavaScript
  • HTML
  • CSS
  • Minimax (alfa-beta)
  • Node.js Test Runner
  • Vercel

Overview

A tic-tac-toe game that runs in the browser. Besides the classic 3×3 game, it has 4×4 and 5×5 boards where every three in a row scores a point until the board is full. Play a friend on the same device or the computer on easy, medium or hard, which never loses on 3×3. Turkish and English, dark and light theme, full keyboard support.

01 · Problem

Classic 3×3 tic-tac-toe always ends in a draw between two good players and gets boring after a few games. On bigger boards, the "first three in a row wins" rule ends the game within a few moves. Most sample apps only offer two-player mode, and when there is a computer opponent it is either missing or too easy to beat.

02 · Solution

I added a scoring rule for 4×4 and 5×5 boards: every three in a row scores a point and play continues until the board is full. The computer has three levels, and the hard level looks ahead with minimax and alpha-beta pruning, staying fast on bigger boards with a heuristic evaluation. The game rules are separate from the UI and use immutable state, so they are verified with unit tests without a browser. Saved data is validated, text is never written with innerHTML, and the site is served with security headers (CSP).

03 · Outcome

A game live at tictactoe.miracdeprem.com that works on phones and desktops. The hard level never lost in 50 tested games on 3×3, and on 5×5 it picks a move in about 0.1 seconds. 22 unit tests cover the rules, the AI and storage.