Modified Connect 4 Agent
A Java Swing app that builds game-playing agents for a modified Connect 4 with adversarial search — minimax, alpha-beta pruning and a transposition table — lets a human face them, and runs agent-versus-agent tournaments as a benchmark.
Modified Connect 4 Agent
Practice 6 for the Advanced Algorithms course (21747) at the Universitat de les Illes Balears. A Java Swing application, on a Model–View–Controller architecture, that builds game-playing agents for a modified version of Connect 4 using adversarial search, lets a human face them, and runs agent-versus-agent tournaments as a benchmark.
The game
The board is a Connect-4 variant, and the task is to build an agent that plays it well. The strongest agent uses minimax with alpha-beta pruning: it explores the game tree, assumes the opponent plays optimally, prunes branches that cannot change the decision, and cuts off at a depth bounded by a heuristic evaluation of non-terminal positions — sped up further with a transposition table so equivalent positions are not searched twice. Alongside it the app ships a spectrum of agents, from trivial to probabilistic, so their strength and cost can be compared head to head.
About
- A ladder of agents — behind a common
GameAgentinterface: a random agent, a greedy agent, a Monte Carlo agent (random playouts), a probabilistic agent, and a strong alpha-beta agent with iterative search, a heuristic evaluator, transposition caching and bound handling; a factory wires them up from configuration. - Search internals — a shared abstract search agent centralizes the alpha-beta machinery, metrics report nodes explored, cutoffs and chosen move, and a timeout exception plus cancellation token keep the UI responsive under a time budget.
- Game rules — the modified Connect-4 mechanics, including its special move types, live in dedicated rule, line-scan and move-parser classes.
- Three workflows, one shared view — human-vs-agent and agent-vs-agent game modes with an animated board, and a benchmark tab that plays whole tournaments and aggregates win rates, decision times and search effort per agent.
- MVC +
Notify/Reporter— the controller runs matches and tournaments on background threads and streams snapshots, progress and telemetry through the message contract.
Executing the project
Requires a JDK 17 or newer — plain Java with Swing, no external dependencies or build tool. Open the P6/ folder in IntelliJ IDEA and run practice6.Main. Play against an agent in the game tab, or set up an agent-versus-agent tournament in the benchmark tab to compare their win rates and search cost.