Game Design• Patterns: Singleton
Tic Tac Toe
Easy
Problem Summary
Design a modular Tic Tac Toe game supporting two players on an N x N board with dynamic win-checking.
Functional Scope
- Support customizable board sizes (default 3x3).
- Alternating turn sequence for Player X and Player O.
- Check win condition in O(1) time after each move.
- Detect draw states when all cells are filled without a winner.
Entity-Relationship (ER) Schema
GameEngine [1] <---> [1] Board GameEngine [1] <---> [2] Player Board [1] <---> [N*N] Cell Cell [1] <---> [1] Symbol
Design Approach
To check wins in O(1) time, keep rows and cols count arrays for each player symbol, along with main and anti-diagonal counters.
Core Classes & Models
Board (Holds grid cells)Player (Symbol: X or O, Name)GameEngine (Runs turn iterations and checks states)
Code Blueprint
public enum Symbol { X, O, EMPTY }
public class Board {
private Symbol[][] grid;
private int size;
public Board(int size) {
this.size = size;
grid = new Symbol[size][size];
}
public boolean makeMove(int r, int c, Symbol s) {
if (grid[r][c] != Symbol.EMPTY) return false;
grid[r][c] = s;
return true;
}
}