A RTIFICIAL I NTELLIGENCE Games. G AMES AND C OMPUTERS Games offer concrete or abstract competitions...

40
ARTIFICIAL INTELLIGENCE Games

Transcript of A RTIFICIAL I NTELLIGENCE Games. G AMES AND C OMPUTERS Games offer concrete or abstract competitions...

ARTIFICIAL INTELLIGENCE

Games

GAMES AND COMPUTERS Games offer concrete or abstract competitions

“I’m better than you!”

Some games are amenable to computer treatment mostly mental activities well-formulated rules and operators accessible state

Others are not emphasis on physical activities rules and operators open to interpretation

state not (easily or fully) accessible

2

DEFINING COMPUTER GAMES

Video game / computer game “a mental contest, played with a computer according to

certain rules for amusement, recreation, or winning a stake” [Zyda, 2005]

Serious game a mental contest, played with a computer in accordance

with specific rules, that uses entertainment to further training or education [modified from Zyda, 2005]

[Zyda, 2005] Michael Zyda, “From Visual Simulation to Virtual Reality to Games,” IEEE Computer, vol. 39, no. 9, pp. 25-32.

3

WHAT ARE AND WHY STUDY GAMES?

Games are a form of multi-agent environment What do other agents do and how do they affect our

success? Cooperative vs. competitive multi-agent

environments. Competitive multi-agent environments give rise to

adversarial search a.k.a. games

Why study games? Fun Interesting subject of study because they are hard

4

RELATION OF GAMES TO SEARCH

Search – no adversary Solution is (heuristic) method for finding goal Heuristics and CSP techniques can find optimal

solution Evaluation function: estimate of cost from start to

goal through given nodes Examples: path planning, scheduling activities

Games – adversary Solution is strategy (strategy specifies move for

every possible opponent reply). Time limits force an approximate solution Evaluation function: evaluate “goodness” of

game position Examples: chess, checkers, Othello, backgammon

5

ASPECTS OF COMPUTER GAMES Story

defines the context and content of the game

Art presentation of the game to the user

emphasis on visual display, sound

Software implementation of the game on a computer

Purpose entertainment training education

6

EXAMPLES

7

EXAMPLES

8

GAME ANALYSIS Often deterministic

the outcome of actions is known sometimes an element of chance is part of the game

e.g. dice

Two-player, turn-taking one move for each player

Zero-sum utility function what one player wins, the other must lose

Often perfect information fully observable, everything is known to both players

about the state of the environment (game) not for all games

e.g. card games with “private” or “hidden” cards 9

TYPES OF GAMES

10

GAMES AS ADVERSARIAL SEARCH Many games can be formulated as search

problems

The zero-sum utility function leads to an adversarial situation in order for one agent to win, the other necessarily

has to lose

Factors complicating the search task potentially huge search spaces elements of chance multi-person games, teams time limits

11

SINGLE-PERSON GAME Conventional search problem

identify a sequence of moves that leads to a winning state

examples: Solitaire and Rubik’s cube little attention in AI

Some games can be quite challenging some versions of solitaire

12

CONTINGENCY PROBLEM Uncertainty due to the moves and motivations of

the opponent tries to make the game as difficult as possible for the

player attempts to maximize its own, and thus minimize the

player’s utility function value

13

TWO-PERSON GAME Games with two opposing players

often called MIN and MAXusually MAX moves first, then they take turns

MAX wants a strategy to find a winning state no matter what MIN does

MIN does the sameor at least tries to prevent MAX from winning

Perfect Decisions traverse all relevant parts of the search tree often impractical because of time and space limitations

14

EXAMPLE TRIVIAL GAME

Deal four playing cards out, face up Player 1 chooses one, player 2 chooses one

Player 1 chooses another, player 2 chooses another

And the winner is….Add the cards up The player with the highest even number

Scores that amount

15

ENTIRE SEARCH SPACE

16

MOVING THE SCORES FROM THE BOTTOM TO THE TOP

17

MOVING A SCORE WHEN THERE’S A CHOICE

Use minimax assumption

18

CHOOSING THE BEST MOVE

19

MINIMAX STRATEGY

Optimal strategy for MAX

generate the whole game tree

calculate the value of each terminal state

starting from the leaf nodes up to the root

MAX selects the value with the highest node

MAX assumes that MIN in its move will select

the node that minimizes the value

assumes that both players play optimally

20

MINIMAX PROPERTIES Based on depth-first

recursive implementation

Time complexity is O(bm) exponential in the number of moves

Space complexity is O(bm) where b is the branching factor, m the maximum

depth of the search tree

21

MINIMAX EXAMPLE

terminal nodes: values calculated from the utility function

4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3

22

MINIMAX EXAMPLE

other nodes: values calculated via minimax algorithm

Min

4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3

4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3

23

MINIMAX EXAMPLE

Max

Min

4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3

4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3

7 6 5 5 6 4

24

MINIMAX EXAMPLE

Max

Min

Min

4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3

4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3

7 6 5 5 6 4

5 3 4

25

MINIMAX EXAMPLE

Max

Max

Min

Min

4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3

4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3

7 6 5 5 6 4

5 3 4

5

26

MINIMAX EXAMPLE

moves by Max and countermoves by Min

Max

Max

Min

Min

4 7 9 6 9 8 8 5 6 7 5 2 3 2 5 4 9 3

4 7 6 2 6 3 4 5 1 2 5 4 1 2 6 3 4 3

7 6 5 5 6 4

5 3 4

5

27

IMPERFECT DECISIONS Complete search is impractical for most games

Alternative: search the tree only to a certain depth requires a cutoff-test to determine where to stop uses a heuristics-based evaluation function to

estimate the expected utility of the game from the leave nodes

28

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 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

29

ALPHA-BETA PRUNING

Certain moves are not considered won’t result in a better evaluation value

Applies to moves by both players indicates the best choice for Max so far never

decreases indicates the best choice for Min so far never

increases

Extension of the minimax approach results in the same move as minimax, but with less

overhead prunes uninteresting parts of the search tree

30

ALPHA-BETA EXAMPLE 1

we assume a depth-first, left-to-right search as basic strategy

the range of the possible values for each node are indicated initially [-∞, +∞]

Max

Min[-∞, +∞]

5[-∞, +∞]

best choice for Max ? best choice for Min?

31

ALPHA-BETA EXAMPLE 2

Min obtains the first value from a successor node

Max

Min

7

[-∞, 7]

5[-∞, +∞]

best choice for Max ? best choice for Min7

32

ALPHA-BETA EXAMPLE 3

Min obtains the second value from a successor node

Max

Min

7 6

[-∞, 6]

5[-∞, +∞]

best choice for Max ? best choice for Min6

33

ALPHA-BETA EXAMPLE 4

Min obtains the third value from a successor node this is the last value from this sub-tree, and the exact value is

known Max now has a value for its first successor node, but hopes

that something better might still come

Max

Min

7 6 5

5

5[5, +∞]

best choice for Max 5 best choice for Min5

34

ALPHA-BETA EXAMPLE 5

Min continues with the next sub-tree, and gets a better value Max has a better choice from its perspective, however, and

will not consider a move in the sub-tree currently explored by Min initially [-∞, +∞]

Max

Min

7 6 5

5

5

3

[5, +∞]

best choice for Max 5 best choice for Min3

[-∞, 3]

35

ALPHA-BETA EXAMPLE 6

Min knows that Max won’t consider a move to this sub-tree, and abandons it

this is a case of pruning, indicated by

Max

Min

7 6 5

5

5

3

[5, +∞]

best choice for Max 5 best choice for Min3

[-∞, 3]

36

ALPHA-BETA EXAMPLE 7

Min explores the next sub-tree, and finds a value that is worse than the other nodes at this level

if Min is not able to find something lower, then Max will choose this branch, so Min must explore more successor nodes

Max

Min

7 6 5 6

5

3

best choice for Max 5 best choice for Min3

5

[5, +∞]

[-∞, 3] [-∞, 6]

37

ALPHA-BETA EXAMPLE 8

Min is lucky, and finds a value that is the same as the current worst value at this level

Max can choose this branch, or the other branch with the same value

Max

Min

7 6 5 6

5

3

best choice for Max 5 best choice for Min3

5

[5, +∞]

[-∞, 3] [-∞, 5]

5

38

ALPHA-BETA EXAMPLE 9

Min could continue searching this sub-tree to see if there is a value that is less than the current worst alternative in order to give Max as few choices as possible this depends on the specific implementation

Max knows the best value for its sub-tree

Max

Min

7 6 5 6

5

3

best choice for Max 5best choice for Min3

5

5

[-∞, 3] [-∞, 5]

5

39

ALPHA-BETA EXAMPLE OVERVIEW

some branches can be pruned because they would never be considered after looking at one branch, Max already knows that they will

not be of interest since Min would choose a value that is less than what Max already has at its disposal

Max

Min

7 6 5 6 5 4

5 <=5

5

3 6 4

<= 3

5

best choice for Max 5 best choice for Min7 -> 6 -> 5 -> 3

40