-
-
Expanded 5x5 board (4-in-a-row) powered by a depth-limited Minimax AI bot with Alpha-Beta Pruning.
-
Accessibility settings dialog with colorblind modes, text scaling, high contrast, readable font, and reduce motion options.
-
Classic 3x3 board showcasing glowing winning strike-through animations and distinct geometric shapes for X and O.
-
Match summary dialog and particle effects powered by HTML5 Canvas and zero-dependency Web Audio synthesis.
Inspiration
Classic board games like Tic Tac Toe are often treated as trivial beginner exercises—frequently built with static UIs, no sound, poor keyboard support, and zero consideration for players with visual or motor impairments. I wanted to turn this familiar classic into a polished, inclusive, and mathematically engaging web experience from scratch, without relying on heavy game engines, external audio files, or third-party UI libraries.
What it does
Tic Tac Toe: Unbeatable Minimax & Accessible Web Game is a zero-dependency browser game playable on both classic 3×3 (3-in-a-row) and expanded 5×5 (4-in-a-row) boards.
Key highlights include:
- Dual-Difficulty AI Bot: Switch between Easy (randomized moves) and Hard (Minimax algorithm optimized with Alpha-Beta Pruning).
- Match & Round System: Play endless sessions or structured matches (3, 5, 7, or 10 rounds) with alternating starting turns and per-board score tracking.
- Accessibility-First Design: Features an onboarding accessibility dialog with colorblind modes (Protanopia/Deuteranopia, Tritanopia, Monochrome), adjustable text scaling, high-contrast mode, dyslexia-friendly typography, and
prefers-reduced-motioncompliance. X and O also maintain distinct geometric shapes so gameplay never relies on color alone. - Full Keyboard & Screen Reader Support: Navigate the board and dialogs entirely with Arrow keys or
WASD, with live move announcements powered byaria-live. - Synthesized Audio & Canvas VFX: Real-time procedural sound effects generated via the Web Audio API (zero
.mp3assets) paired with<canvas>particle effects (sparks, confetti, falling ash, and match-win fireworks) and mobile haptic feedback. - Bilingual Interface: Instant toggle between English and Indonesian with persistent preferences saved in
localStorage.
How I built it
The entire application is engineered in vanilla TypeScript, HTML5, and CSS3 using clean modular architecture (game.ts, ticTacToe.ts, sound.ts, effects.ts, setting.ts, prefs.ts, i18n.ts, and storage.ts):
- Game AI & Decision Tree (
game.ts): Implemented the Minimax algorithm with Alpha-Beta Pruning and center-first move ordering: $$\text{score} = \max(\alpha, \min(\beta, \text{minimax}(\text{state}, \text{depth}, \alpha, \beta)))$$ On the 3×3 grid, the bot searches to full depth ($d = 9$), making it mathematically unbeatable. For the larger 5×5 grid ($25!$ possible states), the search is capped at depth $d = 4$ and guided by a custom heuristicevaluate()function that scores potential winning lines generated dynamically viabuildLines(size, k). - Procedural Audio (
sound.ts): Built a lightweight synthesizer usingAudioContextoscillators and gain envelopes to produce distinct tones for X, O, victories, defeats, and draws—safely initialized upon first user interaction to respect browser autoplay policies. - Particle Engine (
effects.ts): Created a 2D<canvas>overlay that renders physics-based particles and automatically disables itself when reduced motion is toggled on.
Challenges I ran into
- Heuristic Sign Inversion on the 5×5 Board: During development, the 5×5 Hard bot was unexpectedly easy to beat. Debugging
evaluate()revealed that opponent marks were accidentally being scored in favor of the bot while an evaluation branch remained unreachable—causing the AI to evaluate board states in reverse. After fixing the heuristic logic and running automated bot-vs-bot simulations, the patched AI defeated the old version 37 out of 40 rounds. - Balancing Search Depth vs. Frame Rate: Searching deep trees on a 5×5 board in single-threaded browser JavaScript can freeze the UI. Combining center-biased move ordering with Alpha-Beta Pruning allowed the AI to prune suboptimal branches early and respond instantaneously.
- Dialog & Keyboard Focus Trapping: Ensuring
WASDand Arrow key navigation worked seamlessly both inside the game grid and across modal dialogs (Accessibility, Game Settings, Match Results) without breaking standardTabnavigation required careful focus management.
Accomplishments that I m proud of
- Achieving zero runtime dependencies—no frameworks, no external audio files, and no sprite sheets—while still delivering rich visuals, procedural sound, and particle physics.
- Making accessibility a core architectural pillar rather than an afterthought, ensuring full playability via keyboard and screen readers.
- Catching and validating a subtle AI evaluation bug through automated simulation testing.
What I learned
- How move ordering dramatically impacts the pruning efficiency of Alpha-Beta search in larger state spaces like 5×5 boards.
- How to synthesize clean, responsive game audio purely with mathematical waveforms in the Web Audio API.
- Practical patterns for building inclusive web interfaces using ARIA live regions, semantic HTML
<dialog>elements, and motion preferences.
Built With
- accessibility
- canvas
- css3
- html5
- javascript
- typescript
- vite
- web-audio-api