CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

67
CPSC 322 Introduction to Artificial Intelligence October 22, 2004
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    217
  • download

    3

Transcript of CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Page 1: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

CPSC 322Introduction to Artificial Intelligence

October 22, 2004

Page 2: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Things...

Office hours today from 3:30 to 4:30 pm

Bring me your first midterms beforethe second midterm if you want to beretested on problem 3

asgn3 will be posted this evening

Jessica Hodgins talk, Thursday,October 28, 1-2pm, MacLeod 214

Page 3: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Helpful CILOG stuffCounting elements in a list

/* This works in Prolog, but not in CILOG */length([H|T],N) <- N > 0 & N1 is N-1 & length(T,N1).length([],0).

/* This works in CILOG */length([H|T],X,Y) <- X1 is X+1 & length(T,X1,Y).length([],X,X).

cilog: ask length([a,b,c],0,X). Answer: length([a, b, c], 0, 3).

Page 4: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Helpful CILOG stuffSorting numeric elements in a list using insertion sort

insert(X,[],[X]).insert(X,[Y|Ys],[X,Y|Ys]) <- X =< Y. insert(X,[Y|Ys],[Y|Zs]) <- X > Y & insert(X,Ys,Zs).

sort([],[]).sort([X|Xu],Ys) <- sort(Xu,Zs) & insert(X,Zs,Ys).

Page 5: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

The Joy of Hex

The game of hexapawn

• 3 x 3 board • 3 pawns on each side • movement of pawns:

• white moves first• pawn can move straight ahead one space if that space is empty• pawn can move diagonally one space forward to capture opponent’s pawn occupying that space

Page 6: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

The Joy of Hex

The game of hexapawn

• 3 ways to win:

• capture all your opponent’s pawns• one of your pawns reaches the opposite end of the board• it’s your opponent’s turn but your opponent can’t move

Page 7: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Two Questions

Second, how do you know which move to make?

Use heuristic knowledge, of course! In this case, weapply this very crude board evaluation function:

if you have won then board value = +10else if opponent has won then board value = -10else board value = number of your pawns - number of opponent’s pawns

The board evaluation function is applied like this....

Page 8: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - -

B B B

your --> - W W - W W - W W

responses B - - W B - W - B

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

Page 9: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - -

B B B

your --> - W W - W W - W W

responses B - - W B - W - B

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

0 1 1 -1 -10 -10 0 -1

Page 10: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - -

B B B

your --> - W W - W W - W W

responses B - - 0 W B - -10 W - B -10

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

0 1 1 -1 -10 -10 0 -1

Page 11: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - - 0

B B B

your --> - W W - W W - W W

responses B - - 0 W B - -10 W - B -10

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

0 1 1 -1 -10 -10 0 -1

Page 12: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - - 0

B B B

your --> - W W

response B - - 0

B - B

opp’s

moves

--> - - W - - W - W -

W - - B W - B - W

B - B B - B B - B

0 1 1

Page 13: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

What if white makes an unexpected move?

Page 14: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - - 0

B B B

your --> - W W

response B - - 0

B - B

opp’s

move

--> - - W

W - -

B - B

0

not this...

Page 15: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - - 0

B B B

your --> - W W

response B - - 0

B - B

opp’s

move

--> - - W

B W -

B - B

1

...but this

Page 16: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

What if white makes a different move?

Apply this search technique again to white’s move andmake your next move accordingly

Page 17: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

your - W W

move --> B - -

B - B

opponent’s - - W

move --> B W -

B - B

Page 18: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

your - W W

move --> B - -

B - B

opponent’s - - W

move --> B W -

B - B

your B - W - - W - - W - - W

responses -> - W - B B - B B - B W B

B - B - - B B - - B - -

opponent’s - - - - - - - - - - - - - - W - - W

moves --> B W - B B W B W - B B W B - B B - B

- - B - - B B - - B - - W - - B W -

Page 19: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

your - W W

move --> B - -

B - B

opponent’s - - W

move --> B W -

B - B

your B - W - - W - - W - - W

responses -> - W - B B - B B - B W B

B - B - - B B - - B - -

10

opponent’s - - - - - - - - - - - - - - W - - W

moves --> B W - B B W B W - B B W B - B B - B

- - B - - B B - - B - - W - - B W -

1 2 1 2 -10 -10

Page 20: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

your - W W

move --> B - -

B - B

opponent’s - - W

move --> B W -

B - B

your B - W - - W - - W - - W

responses -> - W - B B - 1 B B - 1 B W B -10

B - B - - B B - - B - -

10

opponent’s - - - - - - - - - - - - - - W - - W

moves --> B W - B B W B W - B B W B - B B - B

- - B - - B B - - B - - W - - B W -

1 2 1 2 -10 -10

Page 21: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

your - W W

move --> B - -

B - B

opponent’s - - W

move --> B W - 10

B - B

your B - W - - W - - W - - W

responses -> - W - B B - 1 B B - 1 B W B -10

B - B - - B B - - B - -

10

opponent’s - - - - - - - - - - - - - - W - - W

moves --> B W - B B W B W - B B W B - B B - B

- - B - - B B - - B - - W - - B W -

1 2 1 2 -10 -10

Page 22: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

your - W W

move --> B - -

B - B

opponent’s - - W

move --> B W - 10

B - B

your B - W

response -> - W -

B - B

10

Page 23: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

What if ...?

...way back at the beginning there was an obvious winfor you in your search space?

Page 24: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - -

B B B

your --> - W W - W W - W W

responses B - - W B - W - B

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

0 1 1 -1 -10 -10 +10 -1

Page 25: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - -

B B B

should you

move here?

your --> - W W - W W - W W

responses B - - W B - W - B

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

0 1 1 -1 -10 -10 +10 -1

Page 26: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

W W W

- - -

B B B

opponent’s - W W

move --> W - -

B B B

NOOOOO!!!!

your --> - W W - W W - W W

responses B - - W B - W - B

B - B B - B B B -

opp’s

moves

--> - - W - - W - W - - W - - W - - W W - - W - - W

W - - B W - B - W W W - W B W - - B W W B W - W

B - B B - B B - B B - B B - B B W - B B - B B -

0 1 1 -1 -10 -10 +10 -1

Page 27: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Game search

(also known as adversarial search) hasthese components:

move (or board) generator

static board evaluation function (this is the heuristic part - it doesn’t generate moves or look ahead - it’s static)

minimax algorithm to alternately propagate minima and maxima upward from “bottom”

Page 28: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmStart with the following:

a) there are two players, MAX and MINb) it’s MAX’s turn to movec) MAX has a static board evaluation function that returns

bigger values if a board is favorable to MAXd) the evaluation function gets better as the game gets

closer to a goal state (else why bother to generatethe game space?)

e) MAX believes that MIN’s evaluation function is nobetter than MAX’s (if that’s not true, then MAXshould at least avoid betting money on this game)

Page 29: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm1. Generate the game tree to as many levels (plies) that time and space

constraints allow. The top level is called MAX (as in it’s now MAX’s turn to move), the next level is called MIN, the next level is MAX, and so on.

2. Apply the evaluation function to all the terminal (leaf) states/boards to get “goodness” values

3. Use those terminal board values to determine the values to be assigned to the immediate parents:

a) if the parent is at a MIN level, then the value is the minimum of the values of its childrenb) if the parent is at a MAX level, then the value is the maximum of the values of its children

4. Keep propagating values upward as in step 3

5. When the values reach the top of the game tree, MAX chooses the move indicated by the highest value

Page 30: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm1. Generate the game tree to as many levels (plies) that time and space

constraints allow. The top level is called MAX (as in it’s now MAX’s turn to move), the next level is called MIN, the next level is MAX, and so on.

2. Apply the evaluation function to all the terminal (leaf) states/boards to get “goodness” values

3. Use those terminal board values to determine the values to be assigned to the immediate parents:

a) if the parent is at a MIN level, then the value is the minimum of the values of its childrenb) if the parent is at a MAX level, then the value is the maximum of the values of its children

4. Keep propagating values upward as in step 3

5. When the values reach the top of the game tree, MAX chooses the move indicated by the highest value

Page 31: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

Page 32: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

Page 33: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

Page 34: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

Page 35: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

Page 36: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm1. Generate the game tree to as many levels (plies) that time and space

constraints allow. The top level is called MAX (as in it’s now MAX’s turn to move), the next level is called MIN, the next level is MAX, and so on.

2. Apply the evaluation function to all the terminal (leaf) states/boards to get “goodness” values

3. Use those terminal board values to determine the values to be assigned to the immediate parents:

a) if the parent is at a MIN level, then the value is the minimum of the values of its childrenb) if the parent is at a MAX level, then the value is the maximum of the values of its children

4. Keep propagating values upward as in step 3

5. When the values reach the top of the game tree, MAX chooses the move indicated by the highest value

Page 37: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

Page 38: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

Page 39: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm1. Generate the game tree to as many levels (plies) that time and space

constraints allow. The top level is called MAX (as in it’s now MAX’s turn to move), the next level is called MIN, the next level is MAX, and so on.

2. Apply the evaluation function to all the terminal (leaf) states/boards to get “goodness” values

3. Use those terminal board values to determine the values to be assigned to the immediate parents:

a) if the parent is at a MIN level, then the value is the minimum of the values of its childrenb) if the parent is at a MAX level, then the value is the maximum of the values of its children

4. Keep propagating values upward as in step 3

5. When the values reach the top of the game tree, MAX chooses the move indicated by the highest value

Page 40: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

Page 41: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

5 -3 8 -12 7 -42 13 -10 -8

Page 42: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm1. Generate the game tree to as many levels (plies) that time and space

constraints allow. The top level is called MAX (as in it’s now MAX’s turn to move), the next level is called MIN, the next level is MAX, and so on.

2. Apply the evaluation function to all the terminal (leaf) states/boards to get “goodness” values

3. Use those terminal board values to determine the values to be assigned to the immediate parents:

a) if the parent is at a MIN level, then the value is the minimum of the values of its childrenb) if the parent is at a MAX level, then the value is the maximum of the values of its children

4. Keep propagating values upward as in step 3

5. When the values reach the top of the game tree, MAX chooses the move indicated by the highest value

Page 43: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

5 -3 8 -12 7 -42 13 -10 -8

Page 44: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

5 -3 8 -12 7 -42 13 -10 -8

5 8 7 13 -8

Page 45: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

5 -3 8 -12 7 -42 13 -10 -8

5 8 7 13 -8

5 7 -8

Page 46: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

5 -3 8 -12 7 -42 13 -10 -8

5 8 7 13 -8

5 7 -8

7

Page 47: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm1. Generate the game tree to as many levels (plies) that time and space

constraints allow. The top level is called MAX (as in it’s now MAX’s turn to move), the next level is called MIN, the next level is MAX, and so on.

2. Apply the evaluation function to all the terminal (leaf) states/boards to get “goodness” values

3. Use those terminal board values to determine the values to be assigned to the immediate parents:

a) if the parent is at a MIN level, then the value is the minimum of the values of its childrenb) if the parent is at a MAX level, then the value is the maximum of the values of its children

4. Keep propagating values upward as in step 3

5. When the values reach the top of the game tree, MAX chooses the move indicated by the highest value

Page 48: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN

MAX

MIN

MAX

5 -3 17 9 8 22 -12 4 7 -42 -9 13 36 -10 -6 -8

5 -3 8 -12 7 -42 13 -10 -8

5 8 7 13 -8

5 7 -8

7

Page 49: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithmMAX (it’s MAX’s turn to move)

MIN 7

7

Page 50: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Minimax algorithm

A simple but powerful technique...

...how powerful is it?

Page 51: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Bluevital statistics:• 200,000,000 moves per second• 480 custom chess-playing chips

1997

Page 52: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

1997

Page 53: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Blue Garry Kasparovvital statistics: vital statistics:• 200,000,000 moves per second • 3 moves per second• 480 custom chess-playing chips • meat

1997

Page 54: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

1997

Page 55: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Blue defeats Garry Kasparov 3.5 games to 2.5 games

Kasparov wins $400,000

Deep Blue wins $700,000

The human race is humiliated

1997

Page 56: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

2003

Garry Kasparov takes on Deep Junior

Page 57: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Junior and Garry Kasparov tie 3 games each

Kasparov wins $500,000 just for being there

Deep Junior and Kasparov split another $500,000

Honor of human race is restored

2003

Page 58: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Junior and Garry Kasparov tie 3 games each

Kasparov wins $500,000 just for being there

Deep Junior and Kasparov split another $500,000

Honor of human race is restored...or is it?

2003

Page 59: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Computer chess rankings have increased about 200 pointsevery 5 years, due in large part to increases in CPU speed

Page 60: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Blue Deep Juniorvital statistics: vital statistics:• 200,000,000 moves per second • 3,000,000 moves per second• 480 custom chess-playing chips • 8 1.6 GHz Intel processors

But speed doesn’t explain Deep Junior

Page 61: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.
Page 62: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.

Deep Junior 8Chess Playing Software by ChessBase

Two Exclusive Bonuses!!Deep Junior 8 - Tips, Tools and Tactics plus Chess Masterpieces

•Deep Junior 8 with  Two Chess Engines!! * Fritz 8 User Interface * Complete Training Functions * Tournament Book * HUGE Database * 3D Boards * Free Access to Playchess.com

•Special Pricing $79.95 (US)

•Deep Junior 8 - Double World Champion!•This chess program, written by the Israelis Amir Ban and Shay Bushinsky, has achieved everything it could wish for. Junior won the Computer Chess World Championship in 2001 and 2002, and it can look back on a string of successes against human beings in tournaments and matches. Unforgettable was its performance against Garry Kasparov in the "Man vs Machine" match in New York in January 2003. With millions of people following on the Internet, double world champion Junior played exciting, imaginative chess to hold the world’s strongest player to a 3:3 draw.

•Deep Junior 8 - You've Got to Love it!•You're going to love Junior 8 and its tremendous attacking style. Junior 8 shows a new quality of computer chess. It has a deep understanding of initiative and attacking chances and likes to sacrifice material more than any other existing chess program. Many of the world's strongest players already use Junior as their analytical partner. It is considered one of the most reliable tactical programs around. Junior’s unique style is very human-like in often preferring positional advantages to material.

from www.chesscentral.com

QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.

Page 63: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.
Page 64: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.
Page 65: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.
Page 66: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.
Page 67: CPSC 322 Introduction to Artificial Intelligence October 22, 2004.