A single-window JavaFX desktop application that packages 20 classic games, each one a visual demonstration of a different AI algorithm — with reinforcement learning (RL) as the central theme.
Each game is a thin shell around one AI technique. The goal is not to build many games, but to use games as containers for a full spectrum of algorithms and trainable AI models. Five of the games learn by themselves and form a complete RL spectrum: tabular Q-learning, Deep Q-Network (DQN), TD-Gammon-style value learning, REINFORCE policy gradient, and neuroevolution.
- Features
- Tech Stack
- Getting Started
- Usage
- Game Catalog
- Reinforcement Learning
- Project Structure
- Architecture
- Testing
- Roadmap
- Acknowledgements
- License
- 20 games, 3 tiers: complete-information board games, single-player puzzles, and real-time arcade games.
- One AI per game: Minimax + Alpha-Beta, MCTS/UCT, Expectimax, A*, IDA*, backtracking, information entropy, and five learning/RL methods.
- Reinforcement learning focus: watch agents train live (progress bar), then play after training.
- Three modes: PvP (two humans), PvE (human vs. AI), EvE (AI self-play, also used as live previews in the lobby).
- Unified architecture: every game is
model(pure rules, no JavaFX) +view(JavaFX UI) +ai(algorithm), plugged into a singleGameinterface. - In-app explanations: each game shows its rules and AI technique in floating bubbles.
- Audio: self-made CC0 8-bit sound effects and CC0 chiptune background music (random track per session, lobby/game playlists, skip & mute).
- No external ML libraries: all neural networks and RL training loops are hand-written in plain Java.
| Layer | Choice |
|---|---|
| Language | Java 21 |
| GUI | JavaFX 21 (Canvas, animation, MediaPlayer) |
| Build | Maven (javafx-maven-plugin, bundled mvnw wrapper) |
| Testing | JUnit 5 |
| AI | Hand-written, no external ML dependencies |
- JDK 21
- No separate Maven install needed (the bundled
mvnwwrapper is used).
# Compile
./mvnw -q compile
# Run the game hub (entry point: hw.games.GameHubApp)
./mvnw -q javafx:run./mvnw -q testPure-logic classes (model / ai) do not depend on JavaFX, so they can be run headlessly — this is how the RL agents are verified to actually converge:
javac -d /tmp/out -cp target/classes MyTest.java
java -cp target/classes:/tmp/out MyTestPick a mode at the top of the lobby, then click a game card to enter it.
| Mode | Meaning |
|---|---|
| PvP | Two human players |
| PvE | Human vs. AI |
| EvE | AI self-play (watch only; also the lobby card previews) |
Controls
- Board / puzzle games: mouse click to place / select.
- Arcade / real-time games: arrow keys or WASD (Flappy uses Space / W / ↑).
- Bottom-right
?shows the game rules,!shows the AI technique. - Music controls (mute / skip track) are in the top-left of the lobby and bottom-right in game.
| Family | Game | Core Algorithm |
|---|---|---|
| Search / game tree | Tic-Tac-Toe | Full Minimax (unbeatable) |
| Connect Four, Gomoku, Checkers, Chess, Reversi | Minimax + Alpha-Beta | |
| Go 9×9 | MCTS / UCT + random rollout | |
| 2048 | Expectimax | |
| Search / path & constraint | Snake | A* + flood fill |
| Tetris | El-Tetris heuristic | |
| Maze | BFS / Dijkstra / A* (visual comparison) | |
| Sudoku | Backtracking + MRV | |
| Minesweeper | Logic + probability | |
| 15-Puzzle | IDA* (Manhattan + linear conflict) | |
| Wordle | Information entropy | |
| Learning / RL | Backgammon | TD-Gammon (TD(0) self-play) |
| Pong | Tabular Q-learning | |
| Breakout | DQN (NN + replay buffer + target net) | |
| CartPole | REINFORCE policy gradient | |
| Evolution | Flappy Bird | Neuroevolution (GA) |
The five self-learning games form an RL spectrum. All training runs in a background thread with a progress bar; the agent plays only after training finishes.
| Paradigm | Game | Method | Network |
|---|---|---|---|
| Value-based (tabular) | Pong | Q-learning | Q-table |
| Value-based (deep) | Breakout | DQN | MLP(5, 32, 32, 3) |
| Value-based (self-play) | Backgammon | TD-Gammon / TD(0) | MLP(196, 40, 1), sigmoid |
| Policy-based | CartPole | REINFORCE | MLP(4, 64, 64, 2) |
| Evolutionary | Flappy Bird | Genetic algorithm | NN(3, 6, 1) |
DQN and REINFORCE share the same hand-written MLP (ReLU hidden layers, linear output, He initialization, MSE backprop). The trick is in how the training target is set: DQN sets it to the Bellman target r + γ·max Q', while REINFORCE sets it to logits + advantage·(onehot − softmax) so a single MSE step equals one policy-gradient ascent step.
HW/
├── pom.xml # Maven build (JavaFX, JUnit deps)
├── mvnw / mvnw.cmd # Maven wrapper
├── docs/ # Reports and technical notes
└── src/
├── main/java/
│ ├── module-info.java
│ └── hw/games/
│ ├── Game.java # Game interface
│ ├── Mode.java # PVP / PVE / EVE + aiControls()
│ ├── HubView.java # Lobby
│ ├── GameHubApp.java # Entry point (registers all games)
│ ├── GameFrame.java # In-game frame (back / rules / AI bubbles)
│ ├── ui/ # GameStyles, Sound, Icons
│ └── <game>/ # one package per game, e.g. cartpole/
│ ├── XxxGame.java # implements Game
│ ├── model/ # pure rules (no JavaFX)
│ ├── view/ # JavaFX view
│ └── ai/ # algorithm / agent
├── main/resources/sounds/ # CC0 sfx (.wav) + bgm (.mp3) + CREDITS.txt
└── test/java/hw/games/ # JUnit tests (model / ai)
- Core (4 files):
Game(interface),Mode(enum),HubView(lobby),GameHubApp(entry point). - Per game:
XxxGame(thin adapter) wires togethermodel/view/ai. - Separation of concerns:
modelholds rules and never imports JavaFX, so AI can copy game state and simulate at high speed in the background.viewextendsBorderPanewith a fixed constructor(Runnable onBack, Mode mode).aiconsumes a model state and returns a move (or exposestrain()/act()). - Adding a game is an Open/Closed change: implement
Game(plusmodel/view/ai) and add one line to the games list inGameHubApp.
- JUnit pure-logic tests for TicTacToe, Go, Chess, 15-Puzzle, Sudoku, and Wordle.
- RL agents are validated headlessly (e.g., CartPole reaches the 500-step cap after about 300 training episodes).
Code is released under the MIT License. Audio assets are CC0 (public domain).
