Professional Documents
Culture Documents
Usman Ghani
2022613.
Introduction:
Connect Four is a popular two-player strategy game where players aim to
create a line of four of their colored discs either vertically, horizontally, or
diagonally. The minimax search algorithm is commonly used to determine
the best move in Connect Four. However, in the worst-case scenario of
starting with an empty board, the algorithm faces challenges due to the vast
search space. This report explores various strategies to enhance the efficiency
of minimax search in Connect Four.
The initial state of the game is an empty grid of 7 columns and 6 rows.
Actions:
Each player can take an action by selecting one of the columns (numbered
from 1 to 7) where they want to drop their colored disc.An action results in
placing a disc of the player's color into the lowest available empty slot within
the selected column.
Transition Model (Result Function):
Given a current state and an action, the transition model determines the
resulting state.When a player selects a column, their colored disc is dropped
into the lowest available empty slot in that column, effectively modifying the
current state of the game.
Goal State (Terminal State and Utility):The game reaches a terminal state
when one player successfully forms a horizontal, vertical, or diagonal line of
four of their own discs, indicating a win.If the grid becomes full without
either player achieving a winning condition, the game ends in a draw. The
utility function assigns values to terminal states:
If Player A wins, the utility value is +1.
If Player B wins, the utility value is -1.
If the game ends in a draw, the utility value is 0.
1. Move Ordering:
Move ordering prioritizes certain moves to improve alpha-beta pruning
efficiency. Strategies like center-based move ordering can reduce the search
space by focusing on moves closer to the center column, where more winning
opportunities often arise.
class MinimaxAgent:
def __init__(self, max_depth=3):
self.max_depth = max_depth
best_action = None
best_value = -float('inf')
2. Depth Limitation:
Limiting the search depth reduces the number of nodes evaluated by the
minimax algorithm, balancing accuracy and computational complexity. By
setting a maximum depth, the algorithm explores a smaller portion of the
game tree, leading to faster decision-making.
3. Heuristic Evaluation:
Heuristic evaluation functions estimate the value of game states at a given
depth, providing approximate values for non-terminal states. These heuristics
enable the algorithm to make informed decisions without exhaustively
searching the entire game tree.
4.Game Environment:
import numpy as np
def empty_board(shape=(6, 7)):
return np.full(shape=shape, fill_value=0)
print(empty_board())
[[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]
[0 0 0 0 0 0 0]]
Conclusion:
In conclusion, employing strategies such as move ordering, depth limitation,
heuristic evaluation, transposition tables, parallelization, and iterative
deepening significantly enhances the efficiency of minimax search in
Connect Four. By implementing these techniques, the algorithm can make
informed decisions efficiently, even in challenging scenarios such as starting
with an empty board. These strategies are essential for developing robust and
high-performing Connect Four agents.