cpsc 322 introduction to artificial intelligence october 22, 2004
Post on 19-Dec-2015
218 views
TRANSCRIPT
CPSC 322Introduction 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
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).
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).
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
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
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....
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 -
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
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
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
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
What if white makes an unexpected move?
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...
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
What if white makes a different move?
Apply this search technique again to white’s move andmake your next move accordingly
your - W W
move --> B - -
B - B
opponent’s - - W
move --> B W -
B - B
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 -
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
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
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
your - W W
move --> B - -
B - B
opponent’s - - W
move --> B W - 10
B - B
your B - W
response -> - W -
B - B
10
What if ...?
...way back at the beginning there was an obvious winfor you in your search space?
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
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
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
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”
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)
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
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
Minimax algorithmMAX (it’s MAX’s turn to move)
Minimax algorithmMAX (it’s MAX’s turn to move)
MIN
Minimax algorithmMAX (it’s MAX’s turn to move)
MIN
MAX
Minimax algorithmMAX (it’s MAX’s turn to move)
MIN
MAX
MIN
Minimax algorithmMAX (it’s MAX’s turn to move)
MIN
MAX
MIN
MAX
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
Minimax algorithmMAX (it’s MAX’s turn to move)
MIN
MAX
MIN
MAX
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
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
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
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
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
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
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
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
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
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
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
Minimax algorithmMAX (it’s MAX’s turn to move)
MIN 7
7
Minimax algorithm
A simple but powerful technique...
...how powerful is it?
Deep Bluevital statistics:• 200,000,000 moves per second• 480 custom chess-playing chips
1997
1997
Deep Blue Garry Kasparovvital statistics: vital statistics:• 200,000,000 moves per second • 3 moves per second• 480 custom chess-playing chips • meat
1997
1997
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
2003
Garry Kasparov takes on Deep Junior
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
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
Computer chess rankings have increased about 200 pointsevery 5 years, due in large part to increases in CPU speed
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
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.