You are on page 1of 33

Department of Computer Sciences

College of Computers & Information Technology

501481-3 Summer 2022

Artificial Intelligence
Chapter 6: Games in AI

1
Single-Person Game
• conventional search problem
– identify a sequence of moves that leads to a
winning state
– examples: Solitaire and Rubik’s cube

• some games can be quite challenging


– Rubik’s cube
• a heuristic solution for this was found by the Absolver
theorem prover
Two-Person Games
• games with two opposing players
– often called MIN and MAX
– usually MAX moves first, then they take turns
– in game terminology, a move comprises two steps (“plies”)
• one by MAX and one by MIN
• MAX wants a strategy to find a winning state
– no matter what MIN does
• MIN does the same
– or at least tries to prevent MAX from winning
• full information
– both players know the full state of the environment
• partial information
– one player only knows part of the environment
– some aspects may be hidden from the opponent, or from both players
Two-Player Game
Types of Games
• Deterministic
• Turn-taking
• 2-player
• Zero-sum
• Perfect information

CS 484 – Artificial Intelligence 5


Types of Games
Deterministic Chance

Perfect Chess, Backgammon,


Information checkers monopoly

Imperfect Bridge,
Information poker

February 7, 2006 AI: Chapter 6: Adversarial Search 6


Perfect Information/Deterministic
Perfect Information/Chance
What Kinds of Games?
For AI, mainly games of strategy with the
following characteristics:

1. Sequence of moves to play


2. Rules that specify possible moves
3. Rules that specify a payment for each move
4. Objective is to maximize your payment

9
Assumptions
• In talking about AI game playing systems, we
make a number of assumptions:

– The opponent is rational – will play to win.


– The game is zero-sum – if one player wins, the
other loses.
– Usually, the two players have complete knowledge
of the game.

CS 484 – Artificial Intelligence 10


AI Games as Search Problems
• Games have a state space search
– Each potential board or game position is a state
– Each possible move is an operation to another
state
– The state space can be HUGE!!!!!!!
• Large branching factor (about 35 for chess)
• Terminal state could be deep (about 50 for chess)

February 7, 2006 AI: Chapter 6: Adversarial Search 11


Games vs. Search Problems
Search in Games is different:
• Unpredictable opponent
• Solution is a strategy
– Specifying a move for every possible opponent
reply
• Time limits
– Unlikely to find the goal…agent must approximate

February 7, 2006 AI: Chapter 6: Adversarial Search 12


Game Trees
• Game trees are used to represent two-player games.
• Alternate moves in the game are represented by
alternate levels in the tree.
• Nodes in the tree represent positions.
• Edges between nodes represent moves.
• Leaf nodes represent won, lost or drawn positions.

CS 484 – Artificial Intelligence 13


Game Trees
• The root of the tree is the initial state
– Next level is all of MAX’s moves (computer)
– Next level is all of MIN’s moves (computer or human)
– …

• Example: Tic-Tac-Toe
– Root has 9 blank squares (MAX)
– Level 1 has 8 blank squares (MIN)
– Level 2 has 7 blank squares (MAX)
– …

February 7, 2006 AI: Chapter 6: Adversarial Search 14


Game Tree (2-player, Deterministic, Turns)

computer’s
turn

opponent’s
turn
The computer is Max.
computer’s
The opponent is Min.
turn
Root has 9 blank squares
opponent’s (MAX)
turn Level 1 has 8 blank squares
(MIN)
Level 2 has 7 blank squares
leaf nodes (MAX)

are
evaluated
15
Minimax
• Minimax is a method used to evaluate game
trees.
• A static evaluator is applied to leaf nodes, and
values are passed back up the tree to
determine the best score the computer can
obtain against a rational opponent.

CS 484 – Artificial Intelligence 16


Minimax Strategy
• Basic Idea:
– Follows DFS strategy
– Choose the move with the highest minimax value
– Choose moves that will lead to a win, even though min is trying to
block
– in choosing, Max will choose best move to get highest points,
assuming Min will choose best move to get lowest points

February 7, 2006 AI: Chapter 6: Adversarial Search 17


Properties of Minimax
• Complete? Yes (if tree is finite)
• Optimal? Yes (if against an optimal opponent), otherwise No
• Time complexity? O(bm)
• Space complexity? O(bm) (depth-first exploration)

• For chess, b ≈ 35, m ≈100 for "reasonable" games


 exact solution completely infeasible

Need to speed it up.

18
Problems with the Minimax Approach
• The problem with minimax search is that the
number of game states it has to examine is
exponential in the number of moves

• To solve the problem, use pruning to eliminate


large parts of the tree from consideration:
Alpha-Beta Pruning

February 7, 2006 AI: Chapter 6: Adversarial Search 19


Pruning
• Simple Definition of PRUNE (DICTIONARY)

– to cut off some of the branches of (a tree or bush)


so that it will grow better or look better
– to reduce (something) by removing parts that are
not necessary or wanted
– to remove anything considered undesirable
Pruning
• discards parts of the search tree
– guaranteed not to contain good moves
– guarantee that the solution is not in that branch or
sub-tree
• if both players make optimal (rational) decisions, they
will never end up in that part of the search tree
• results in substantial time and space savings
– as a consequence, longer sequences of moves can
be explored
– the leftover part of the task may still be
exponential, however
Alpha-Beta Algorithm
• It is based on process of eliminating a branch
of the search tree “pruning” the search tree.

• It is applied as standard minimax tree:

– it returns the same move as minimax


– prunes away branches that are not necessary to
the final decision.
Alpha-Beta Procedure
• The alpha-beta procedure can speed up a
depth-first minimax search.
• Alpha: a lower bound on the value that a max
node may ultimately be assigned
v>

• Beta: an upper bound on the value that a


minimizing node may ultimately be assigned
v<

23
Alpha-Beta Pruning
The idea behind the pruning process is to
recognize when a situation can never be chosen
in minimax no matter what its children-nodes
are:
– Max (3, Min(2,x,y) …) is always ≥ 3
– Min (2, Max(3,x,y) …) is always ≤ 2
– We reach these conclusions without knowing x
and y!

February 7, 2006 AI: Chapter 6: Adversarial Search 24


α-β pruning example
α-β pruning example

26
α-β pruning example

α= 3

Prune
β= 2

• We don’t need to compute


the value at these nodes.
• No matter what it is it can’t
affect the value of the root
node.
α-β pruning example

α= 3

β= 14

28
α-β pruning example

α= 3

β= 5

29
α-β pruning example

30
- Pruning
This technique recognizes when a game tree state can
never be reached in an actual play.

A B C

After looking ahead to here, MAX knows that the utility for
MIN of state B will be 2 or less. Since this cannot beat the
utility already found for state A, MAX knows that B will not
be chosen. So the rest of the subtree can be ignored (pruned)
Examples on AI Game Types
• Real Time Strategy (RTS)
• Role Playing Games (RPG)
• Action games
– First person shooter (FPS)
– Sports games

With goals such as:


– Have more fun: Reasonable challenge with
natural human behavior
– Used to increase difficulty level
– Draws away focus to program more human-
like bots
– Run faster, and use minimal memory
32
AI in Different Game Types
• FPS & RPG
– AI is in opponents, teammates, and extra
characters
• RTS
– AI on all sides
• Sports Games
– AI is in opponents and teammates

33

You might also like