# Introduction To Heuristics - GameCarpenter

Document Sample

```					Connect Four Heuristics

By Stephan Carpenter
AI Opponents
• AI Opponents look at the possible outcomes
of their move of choice
• Most games don’t reach a final state (such as
win, lose, or draw), very quickly.
• The AI needs some other way to check if one
position is better than another.
Enter Heuristics!
• A Heuristic looks at the board and assigns it a
score.
• The higher the score, the better the position is
for the AI, the more likely the AI will win.
• The AI chooses the moves leading to the
position with the highest score
Connect Four Heuristics
• For each window of four blocks which would
result in a win, each side can score points if
they have potential to win using that set.
• Example for X:
– Horizontal of two
– Vertical of one
O
– Diagonal of two              X   X   O
• Blocked windows                X   O   O

generate no potential
Modifying Heuristics
• Overall score is AI score vs. Opponent score.
• Offense Weight - score multiplier for the
points the AI earned
• Defense Weight – score multiplier for the
points opponent earned
• H weight – score multiplier for horizontal
winning potential
• V weight – score multiplier for vertical winning
potential
Modifying Heuristics Continued
• D weight – score multiplier for diagonal
winning potential.
• one weight – number of points given for each
potential window with one piece in it.
• two weight – number of points given for each
potential window with two pieces in it.
• three weight – number of points given for
each potential window with three pieces in it.
Section 2
Minimax Algorithm
• AI chooses the highest score to represent the
result if the choice of what position to go to is
his (max)
• AI chooses the lowest score to represent the
result if the choice of what position to go to is
the opponents (min)
• AI keeps looking further into the future until
the end of game is reached, or heuristic used
Minimax Continued

Initial Position                B0

Position After
AI Move (Max)            Ba          Bb

After Enemy
Move (Min)        Ba1        Ba2    Bb1
Heuristics and Player to Move
• Normally a heuristic when using minimax
needs to score a position differently based on
who gets to move next.
• In the example, the heuristic is only used after
an opponent move.
Advanced Options
• Max depth – How deep to look into the future
for minimax. This is in full moves, or 2 ply. The
number of positions which have to be
evaluated before moving are at most
36^(depth+1) suggest using depth 4 at most.
• Stochastic – Will choose between all equally
valued moves if true instead of first found.
• Tolerance – Allow moves which return as sub-
optimal by this amount or less.
Advanced Options Continued
• Win value – When the AI move results in a
win, this is the value returned. Should be very
high for AI who are designed with winning as
their goal
• Loss value – When the player move will result
in a loss, this is the value returned.
• Draw value – The value returned when the
move resulted in a draw.

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 5 posted: 12/4/2012 language: English pages: 12
pptfiles
About