BACK TO PORTFOLIOENGINEERING CASE STUDY // VERIFIED BUILD
JAVA / GAME DEVELOPMENT

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.

TESTS PASSED47
AI LOSSES0
WINNING LINES8
AI SIDES TESTEDX + O

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.

01

GAME STATE

Immutable Board

  • Cell[9] state model
  • Defensive copying
02

CONTROLLER

Game Controller

  • Turn & input orchestration
  • Session protection
03

MINIMAX ENGINE

Minimax Engine

  • Alpha-Beta pruning
  • Depth-aware scoring
04

SWING VIEW

Custom Swing UI

  • Async AI state
  • Custom 2D rendering
05

VERIFICATION

AI Verification

  • Exhaustive game-tree search
  • 47 automated tests
PIPELINE GRAPH SCHEMATICZERO LOSS VERIFIED ✓
CLICK ANY STAGE TO INSPECT ITS INPUT / OUTPUT SPECDATA FLOW 5 STAGES ✓

2. OVERVIEW

CHALLENGE

Implement an interactive game where the AI must make mathematically optimal decisions while keeping game state, search logic, and UI responsibilities cleanly separated.

SOLUTION

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.

STATUS

Completed · 47 Tests Passing

3. HOW MINIMAX WORKS

SEARCH FLOW
1CURRENT BOARD
2GENERATE LEGAL MOVES
3SIMULATE EACH MOVE
4MINIMAX SEARCH
5ALPHA-BETA PRUNING
6EVALUATE TERMINAL STATES
7SELECT BEST MOVE
SCORE RULES
AI WIN+10 − depth
DRAW0
AI LOSSdepth − 10

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

ASYNC AI FLOWEDT RESPONSIVE ✓
1PLAYER MOVE
2UPDATE BOARD
3AI THINKING
4BACKGROUND WORKER
5MINIMAX + ALPHA-BETA
6SESSION CHECK
7EDT UPDATE
8RENDER AI MOVE

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.

47TESTS PASSED
0AI LOSSES
8WINNING LINES
X + OAI SIDES TESTED

TECH STACK

Java 21SwingMinimaxAlpha-Beta PruningMVCJUnit 5Maven

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.