Core Technologies
- HTML5 - Structure and content of the game
- CSS3 - Styling and animations (including TailwindCSS)
- JavaScript - Game logic and interactivity
- Font Awesome - Icons for X, O, and buttons
- TailwindCSS - Utility-first CSS framework for rapid UI development
Key Algorithms
The AI uses a Minimax algorithm with depth-limited recursion to determine optimal moves:
function minimax(board, depth, isMaximizing) {
// Base cases: check for wins/losses/ties
if (checkWin(currentPlayer)) return 10 - depth;
if (checkWin(opponent)) return -10 + depth;
if (checkTie()) return 0;
if (isMaximizing) {
let bestScore = -Infinity;
// Evaluate all possible moves
return bestScore;
} else {
let bestScore = Infinity;
// Evaluate all possible opponent moves
return bestScore;
}
}
Game Features
- Responsive Design - Works on all device sizes
- Sound Effects - For moves, wins, and losses
- Animations - Smooth transitions and winning highlights
- Player Customization - Toggle between human and AI players
- Score Tracking - Persistent across games
- AI vs AI Mode - Watch the computer play against itself
Game State Management
The game maintains several key state variables:
let board = ['', '', '', '', '', '', '', '', ''];
let currentPlayer = 'X'; // X or O
let gameActive = false; // Game status
let scores = { playerX: 0, playerO: 0, ties: 0 };
let playerTypes = { X: 'human', O: 'ai' };
let lastWinner = null; // For turn alternation