TIC-TAC-TOE WITH
MINIMAX AI
Built a Java 21 Swing Tic-Tac-Toe application with an immutable game-state model, unbeatable Minimax AI with alpha-beta pruning, MVC architecture, asynchronous AI computation, and exhaustive game-tree verification.
1. ARCHITECTURE & PIPELINE
Game state, search logic, and UI responsibilities are cleanly separated. The board is immutable, the Minimax engine is independent of Swing, and the view renders AI decisions computed asynchronously off the Event Dispatch Thread.
GAME STATE
Immutable Board
- Cell[9] state model
- Defensive copying
CONTROLLER
Game Controller
- Turn & input orchestration
- Session protection
MINIMAX ENGINE
Minimax Engine
- Alpha-Beta pruning
- Depth-aware scoring
SWING VIEW
Custom Swing UI
- Async AI state
- Custom 2D rendering
VERIFICATION
AI Verification
- Exhaustive game-tree search
- 47 automated tests
2. OVERVIEW
Implement an interactive game where the AI must make mathematically optimal decisions while keeping game state, search logic, and UI responsibilities cleanly separated.
Built an immutable board model and recursive Minimax engine with alpha-beta pruning, connected through an MVC controller and responsive Swing interface. The AI was exhaustively tested against every legal opponent response.
Completed · 47 Tests Passing
3. HOW MINIMAX WORKS
Depth-aware scoring prefers faster wins and slower losses, and alpha-beta pruning drops branches that cannot improve the current best decision.
4. CONCURRENCY MODEL
AI computation runs outside the Swing Event Dispatch Thread, while session-generation checks prevent stale calculations from modifying a restarted game.
5. BUILD LOG
IMPLEMENTATION
- Modeled the board as an immutable Cell[9] state with defensive copying and terminal-state evaluation.
- Implemented recursive Minimax with depth-aware scoring and alpha-beta pruning.
- Built a custom Swing board with hover states, winning-line rendering, and responsive resizing.
- Added asynchronous AI computation with session-generation protection against stale results.
RESULTS
- 47 automated tests covering board validation, all eight winning configurations, draws, immutability, Minimax decisions, controller flow, and concurrency.
- Exhaustive game-tree verification confirmed that the AI never loses when playing optimally as either X or O.
- Alpha-beta search was validated against unpruned Minimax for equivalent decisions and reduced node exploration.
- The Swing UI remains responsive while AI calculations execute asynchronously.
LESSONS LEARNED
- Immutable game states simplify recursive game-tree exploration because hypothetical moves never mutate the original board.
- Minimax becomes substantially easier to reason about when terminal evaluation, maximizing/minimizing behavior, and depth scoring are separated.
- Alpha-beta pruning improves search efficiency without changing the optimal decision.
- Asynchronous computation introduces a second problem beyond algorithm correctness: stale results must be prevented from modifying newer application state.
6. VERIFICATION
Every claim above is backed by an exhaustive game-tree search across all legal opponent response sequences for both AI=X and AI=O, plus 47 automated JUnit 5 tests.
TECH STACK
Zero runtime dependencies beyond Java/Swing; Maven and JUnit 5 are part of the development environment only. Immutability and concurrency are covered in the case-study sections above.