Game Playing: Artificial Intelligence
Game Playing: Artificial Intelligence
Game Playing
Artificial intelligence : Games
• https://cardgames.io/checkers/
Game playing machines
Chess:
• In 1949, Claude E. Shannon in his paper
“Programming a Computer for Playing Chess”,
suggested Chess as an AI problem for the
community.
• Deep Blue defeated human world champion Gary
Kasparov in a six-game match in 1997.
• In 2006, Vladmir Kramnik, the undisputed world
champion, was defeated 4-2 by Deep Fritz.
Deep Blue : Man vs Machine
Deep Thought : chess playing machine project started in
CMU
Deep Blue : First computer to beat a chess champion in
1996
Kasparov said that he sometimes saw deep intelligence
and creativity in the machine's moves
Game playing machines
Go: b > 300! Google Deep mind Project AlphaGo. In
2016, AlphaGo beat both Fan Hui, the European Go
champion and Lee Sedol the worlds best player.
Game playing : Tree search
Game playing : 8 queens
https://mypuzzle.org/sl
iding
https://www.brainmetri
x.com/8-queens/
Game Playing : Tic Tac Toe
https://playtictactoe.org/
“Search” Solutions !
• The process of looking for a sequence of actions that reaches the goal is
called search.
• A search algorithm takes a problem as input and returns a solution in the
form of an action sequence. Once a solution is found, the actions it
recommends can be carried out. This is called the execution phase.
http://brainmetrix.com/8-queens/
8 Queens Puzzle
8 puzzle problem • http://mypuzzle.org/sliding
Travelling Problem
memory requirements are a bigger problem for breadth-first search than is the execution time.
depth-first search requires storage of only O(bd) nodes, depth-first search would require 156
kilobytes instead of 10 exabytes at depth d = 16, a factor of 7 trillion times less space.
Time complexity :
BFS vs DFS
Breadth first search and depth first
search
Informed Search : Best first search
h(n) = 0.
through n .
g(n) + h(n)
Types of games
>
Minimax example
Minimax example
Minimax example
Minimax example
Minimax example
Minimax algorithm
Properties of minimax
• Optimal (opponent plays optimally) and complete
(finite tree)
• D F S time: O(bd)
• D F S space: O(bd)
– Tic-Tac-Toe
-5 legal moves on average, total of 9 moves (9
plies).
- 59 = 1,953,125
--9! = 362, 880 terminal nodes
– Chess
-b~ 35 (average branching factor)
- d ~ 100 (depth of game tree for a typical game)
--bd~ 35100 ~ 10154 nodes
– G o branching factor starts at 361 (19X19 board)
Multiplayer Games
Case of limited resources
• Problem: In real games, we are limited in time, so we
can’t search the leaves.
• Solution:
1 . R eplace terminal utilities with an
evaluation function for non-
terminal positions.
2. Use pruning: eliminate large parts of the tree.
↵—Ø pruning
= max(3, min(2, X , Y ), 2)
↵—Ø pruning
= max(3, min(2, X , Y ), 2)
= max(3,min(2,X , Y ),2)
= 3
↵—Ø pruning
= max(3, min(2, X , Y ), 2)
= 3
M i n i m a x decisions are independent of t h e values of X and Y .
↵—Ø pruning
= min(3, max(12, A, B ))
= 3
M i n i m a x decisions are independent of t h e values of A and B .
↵—Ø pruning
• Strateg y: Just like minimax, it performs a D F S .
↵—Ø pruning
• Strategy: Just like minimax, it performs a D F S .
• Parameters: Keep track of two bounds
– alpha : largest value for Max across seen children (current lower
bound on MAX’s outcome).
– beta : lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
↵—Ø pruning
• Strategy: Just like minimax, it performs a D F S .
• Parameters: Keep track of two bounds
– alpha : largest value for Max across seen children (current lower
bound on MAX’s outcome).
– beta : lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
• Initialization: alpha = — 1 , b e t a = 1
↵—Ø pruning
• Strategy: Just like minimax, it performs a D F S .
• Parameters: Keep track of two bounds
– ↵: largest value for Max across seen children (current lower
bound on MAX’s outcome).
– Ø: lowest value for MIN across seen children (current upper
bound on MIN’s outcome).
• Initialization: ↵= — 1 , Ø= 1
• Propagation : Send ↵, Øvalues down during the search to be
used for pruning.
– Update ↵, Ø values by propagating upwards values of ter-
minal nodes.
– Update ↵ only at M ax nodes and update Ø only at M in
nodes.
Deep Blue’s 1996 debut in the first Kasparov versus Deep Blue
Deep Blue
Winning a match against the human World Chess Champion
under regulation time control. The games had to play out no
faster than three minutes per move.
In 1996 Deep Blue was even with Kasparov after four games
in the first match. Kasparov pinpointed Deep Blue’s
weaknesses and won the remaining two games easily.
Computation speed alone apparently didn’t suffice.
What caused the problems for Cray Blitz and Deep Blue in the
1984 and 1996 matches? First, they played adaptable human
opponents.
Humans learn !
The 1997 version of Deep Blue included 480 chess chips. Since each
chess chip could search 2 to 2.5 million chess positions/s, the
“guaranteed not to exceed” system speed reached about one billion
chess positions per
second, or 40 tera operations.
Partial g a m e t re e for B a c k g a m m o n .
Stochastic games
Algorithm Ex p e c t i mi n i ma x generalized Minimax to handle chance
nodes as follows:
For a state s:
Expectiminimax(s) =
8
>
< Utility(s) if Terminal-test(s)
maxa2Actions(s) E xpectiminimax( Result( s,a)) if Player(s) = Max
> min a2Actions(s) Expectiminimax(Result(s,a)) if Player(s) = Min
: P
r P (r) Expectiminimax(Result(s,r)) if Player(s) = Chance
Where r represents all chance events (e.g., dice roll), and Re-
sult(s,r) is the same state as s with the result of the chance event is
r.
Games: conclusion
• Games are modeled in AI as a search problem and use heuristic to
evaluate the game.
• Minimax goes all the way down the tree which is not practical give
game time constraints.
• A lpha-B eta pruning can reduce the game tree search which
allow to go deeper in the tree within the time constraints.