This project is a two-player Connect 4 game implementation featuring an AI opponent powered by the Minimax algorithm with Alpha-Beta pruning. The AI simulates optimal play by evaluating future game states and selecting the best possible move while limiting search complexity through depth constraints.
This project demonstrates fundamental concepts in game theory, adversarial search, and artificial intelligence.
Players:
- Two players take turns dropping discs into the board
- One player uses red (MAX) discs
- The other uses blue (MIN) discs
Objective:
Be the first player to connect four discs in a row.
Board:
- 7 columns × 6 rows vertical grid
Gameplay Rules:
- Players alternate turns
- A disc is dropped into a chosen column
- The disc falls to the lowest available position in that column
Winning Conditions:
- Four connected discs horizontally
- Four connected discs vertically
- Four connected discs diagonally
Draw Condition:
- If the board fills completely with no winner, the game ends in a draw
The Minimax algorithm is used for:
- Two-player
- Turn-based
- Deterministic games
Key Concepts:
- One player acts as the Maximizer
- The opponent acts as the Minimizer
- Both players are assumed to play optimally
- The algorithm simulates all possible future moves
- The best move is selected based on maximizing or minimizing the evaluation score
To improve performance, Alpha-Beta pruning is used to:
- Eliminate branches of the game tree that cannot influence the final decision
- Reduce the number of states evaluated
- Allow deeper searches within reasonable execution time
- A
maxDepthparameter limits how deep the Minimax search goes - Necessary due to the large size of the Connect 4 game tree
- Depth is passed recursively through Minimax calls
- Once
maxDepthis reached, the board state is evaluated heuristically
- Returns all valid columns where a disc can be dropped
- Checks only the top cell of each column to determine availability
- Simulates placing a disc in the selected column
- Drops the disc into the lowest available row
- Uses:
Xfor MAX playerOfor MIN player
Evaluates the board state:
1→ MAX player wins-1→ MIN player wins0→ No winner yet
A return value of 0 signals that the game should continue searching deeper until a terminal state or depth limit is reached.
- Java
- Minimax Algorithm
- Alpha-Beta Pruning
- Game Tree Search
- Artificial Intelligence
- Adversarial search
- Decision-making under optimal play assumptions
- Recursive algorithms
- Game state evaluation
- Performance optimization through pruning