game trees
Download
Skip this Video
Download Presentation
Game Trees

Loading in 2 Seconds...

play fullscreen
1 / 27

Game Trees - PowerPoint PPT Presentation


  • 132 Views
  • Uploaded on

Game Trees. Ryan Wilson. Chapter 6. Trees – A Review. Trees are a collection of nodes A Tree has a root node and zero or more sub-trees. Root Node. A. B. E. G. C. D. F. H. I. An Example Tree. Common Traversal Algorithm. Function TraverseTree( node ) visit( node )

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Game Trees' - vega


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
game trees

Game Trees

Ryan Wilson

Chapter 6

trees a review
Trees – A Review
  • Trees are a collection of nodes
  • A Tree has a root node and zero or more sub-trees
slide3

Root Node

A

B

E

G

C

D

F

H

I

An Example Tree

common traversal algorithm
CommonTraversalAlgorithm

Function TraverseTree( node )

visit( node )

for each child of node

TraverseTree( child )

end for

End Function

TraverseTree( root )

computer games
Computer Games
  • Problem: How do we make an intelligent opponent for a human player to compete against?
  • One Possibility:
    • Game Trees
game trees1
Game Trees
  • Treat each state of the game as a node in a tree
  • Search the tree to find the best move
slide7

X

O

X

X

X

O

O

X

X

O

X

O

X

game trees2
Game Trees
  • 3 Components to Implementing a Game Tree:
    • Tree Generator
    • Position Evaluator
    • Minimax Method
slide9

X

Position

Evaluator

O

O

X

X

X

X

O

O

O

X

X

0

X

O

X

X

X

O

X

O

X

X

1 = Computer Wins

0 = Draw

-1 = Human Wins

O

O

X

O

O

O

-1

1

slide10

REMEMBER!

Higher Score

is better for

the computer!

40

MAX

Computer’s Turn

40

20

MIN

Human’s Turn

40

30

60

20

minimax computer
Minimax - Computer

Function FindComputerMove(GameStateNode)

var bestValue

if( terminal )

return evaluate(GameStateNode)

for each child of GameStateNode

value = FindHumanMove(child)

if( value > bestValue )

bestValue = value

end for

End function

minimax human
Minimax - Human

Function FindHumanMove(GameStateNode)

var bestValue

if( terminal )

return evaluate(GameStateNode)

for each child of GameStateNode

value = FindHumanMove(child)

if( value < bestValue )

bestValue = value

end for

End function

demonstration
Demonstration
  • Tic-Tac-Toe!
conclusions
Conclusions
  • In Tic-Tac-Toe, there’s only about 27 legal moves for the computer to consider
    • That’s about 30,000 moves
  • But it’s still kind of slow…
  • Almost 45 seconds to make the first move!
  • Experts estimate 10100 legal moves in Chess!
  • That’s approx. 2333 legal positions!
what can we do
What can we do?
  • Apply the position evaluator to non-terminal nodes
    • Limit the depth of your search through the tree
    • Have to estimate the value of a position
  • Alpha-Beta Pruning
    • “Trim” un-needed portions of the tree
  • Transposition Tables
alpha beta pruning
Alpha-Beta Pruning
  • Don’t need to look at all subtrees of a given node if you can already know which one is best
slide17

Alpha-Pruning

REMEMBER!

Higher Score

is better for

the computer!

>40

MAX

Computer’s Turn

40

<20

MIN

Human’s Turn

40

30

60

20

slide18

Beta-Pruning

REMEMBER!

Higher Score

is better for

the computer!

<100

MIN

Human’s Turn

100

>120

MAX

Computer’s Turn

100

40

120

30

demonstration1
Demonstration
  • Tic-Tac-Toe!
    • With Alpha-Beta Pruning
conclusions1
Conclusions
  • A definite improvement!
  • First move only takes about 4 seconds (about 2000 moves)
transposition tables
Transposition Tables
  • In many games, there are multiple ways to arrive at the same board position…
slide22

O

O

X

X

X

X

O

O

X

X

X

X

transposition tables1
Transposition Tables
  • Once we’ve calculated the value of a given position, we save it in a table so it’s easy to look up.
  • For each position in the tree, look that position up in the table, if it exists, return the value stored in the table.
demonstration2
Demonstration
  • Tic-Tac-Toe!
    • With Alpha-Beta Pruning
    • With Transposition Tables
conclusions2
Conclusions
  • Another improvement!
  • First move only takes about 3 seconds (918 nodes)
  • Almost ½ as many nodes!
game trees3
Game Trees
  • How-To of Game Trees
  • Alpha-Beta Pruning
  • Transposition Tables
references
References
  • DewdneyThe New Turing Omnibus
  • WeissAlgorithms, Data Structures, and Problem Solving with C++
  • WeissData Structures & Algorithm Analysis in C++
ad