A production-grade implementation of the classic Dots and Boxes strategy game featuring real-time online multiplayer, AI opponents with multiple difficulty levels, and a polished dark-themed UI โ built with TypeScript end-to-end.
| Mode | Description |
|---|---|
| ๐ฅ Local Multiplayer | 2โ4 players on the same device, hot-seat style |
| ๐ค vs AI | Play against AI with Easy, Medium, or Hard difficulty |
| ๐ Online Multiplayer | Real-time rooms via Socket.io with shareable invite links |
- Easy โ Random move selection
- Medium โ Greedy strategy: completes boxes, avoids giving away 3-sided boxes
- Hard โ Minimax with alpha-beta pruning (depth 6, full search for โค12 remaining moves)
- Custom player names (persisted in localStorage)
- 4 color presets
- 12 avatar emojis
- 3ร3 to 10ร10 grid sizes
- Automatic box completion detection & scoring
- Turn indicator with active player glow animation
- Game-over overlay with ranked leaderboard & confetti
- Procedural sound effects (Web Audio API โ no external files)
- Shareable room links for online play (
/game/online/:roomId) - Disconnect handling with 30-second reconnection window
- Mute toggle (persisted in localStorage)
dots_and_boxes/
โโโ shared/ # Shared TypeScript package
โ โโโ src/
โ โโโ types.ts # Type definitions (GameState, events, etc.)
โ โโโ constants.ts # Grid sizes, colors, timing constants
โ โโโ gameLogic.ts # Core game logic (applyMove, findCompletedBoxes, etc.)
โ โโโ gameLogic.test.ts # 52 unit tests
โ
โโโ backend/ # Node.js + Express + Socket.io
โ โโโ src/
โ โโโ index.ts # Server entry, health check, graceful shutdown
โ โโโ socket/
โ โ โโโ handlers.ts # Socket event handlers with turn validation
โ โ โโโ validation.ts # Input validation (payloads, line coords)
โ โโโ game/
โ โ โโโ roomManager.ts # Room CRUD, TTL cleanup, disconnections
โ โโโ middleware/
โ โ โโโ rateLimiter.ts # Per-socket sliding window rate limiting
โ โโโ utils/
โ โโโ logger.ts # Structured logging (pino)
โ
โโโ frontend/ # React 19 + TypeScript (CRA)
โ โโโ src/
โ โโโ App.tsx # Router (react-router-dom v6)
โ โโโ routes/
โ โ โโโ Home.tsx # Lobby with player customization
โ โ โโโ Game.tsx # Route wrapper parsing URL params
โ โโโ components/GameBoard/
โ โ โโโ GameBoard.tsx # Main orchestrator (local/AI/online)
โ โ โโโ Board.tsx # Pure rendering (dots, lines, boxes)
โ โ โโโ Scoreboard.tsx # Player scores with turn glow
โ โ โโโ WaitingRoom.tsx# Pre-game lobby with copy link
โ โ โโโ GameOver.tsx # Results, leaderboard, confetti
โ โโโ hooks/
โ โ โโโ useSocket.ts # Socket.io connection lifecycle
โ โ โโโ useGameState.ts# Local game state via shared logic
โ โ โโโ useAI.ts # AI strategies (easy/medium/hard)
โ โโโ utils/
โ โโโ sounds.ts # Procedural Web Audio API sounds
โ
โโโ .github/workflows/
โโโ ci.yml # CI pipeline (build, test, typecheck)
| Layer | Technology |
|---|---|
| Language | TypeScript (strict mode, end-to-end) |
| Frontend | React 19, React Router v6, react-hot-toast, canvas-confetti |
| Backend | Node.js, Express 4, Socket.io 4.8 |
| Shared | Monorepo shared package (dots-and-boxes-shared) |
| Testing | Jest, React Testing Library (86+ tests across packages) |
| CI/CD | GitHub Actions (Node 18 & 20 matrix) |
| Logging | pino (structured JSON logging) |
| Deployment | Vercel (frontend) + Render (backend) |
- Server-side turn validation โ prevents out-of-turn moves
- Input validation โ all payloads validated (grid size, player info, line coordinates)
- Rate limiting โ sliding window per socket (5 moves/sec, 2 rooms/min)
- Room TTL โ automatic cleanup of stale rooms (1 hour)
- Graceful shutdown โ SIGTERM/SIGINT handling with client notification
- Disconnect handling โ 30-second reconnection window for dropped players
- Node.js โฅ 18
- npm
# Clone the repository
git clone https://github.com/DIPESHGOEL27/Dots_and_Boxes.git
cd Dots_and_Boxes
# Install & build the shared package
cd shared && npm install && npm run build && cd ..
# Install backend dependencies
cd backend && npm install && cd ..
# Install frontend dependencies
cd frontend && npm install --legacy-peer-deps && cd ..# Terminal 1: Start the backend
cd backend && npm run dev
# Terminal 2: Start the frontend
cd frontend && npm startThe frontend runs on http://localhost:3000 and the backend on http://localhost:4000.
# Run all tests
cd shared && npm test # 52 tests
cd ../frontend && npx react-scripts test --watchAll=false # 34 testscd shared && npm run build
cd ../backend && npm run build
cd ../frontend && npx react-scripts buildGET /health
โ { status: "ok", uptime: 1234.5, rooms: 3, timestamp: "..." }
| Direction | Event | Payload |
|---|---|---|
| CโS | createRoom |
{ gridSize, maxPlayers, playerInfo } |
| CโS | joinRoom |
{ roomId, playerInfo } |
| CโS | startGame |
{ roomId } |
| CโS | makeMove |
{ roomId, line: [x1,y1,x2,y2] } |
| SโC | roomCreated |
{ roomId } |
| SโC | waitingForPlayers |
{ players, maxPlayers, creator } |
| SโC | startGame |
{ state } |
| SโC | updateGame |
{ state } |
| SโC | gameOver |
{ state, winner, winnerName, isDraw } |
| SโC | playerDisconnected |
{ playerInfo, playerIndex, reconnectTimeout } |
| SโC | playerReconnected |
{ playerInfo, playerIndex } |
MIT โ see LICENSE for details.