download

Matakuliah
Tahun
Versi
: T0264/Intelijensia Semu
: Juli 2006
: 2/1
Pertemuan 15
Game Playing
1
Learning Outcomes
Pada akhir pertemuan ini, diharapkan mahasiswa
akan mampu :
• << TIK-99 >>
• << TIK-99>>
2
Outline Materi
•
•
•
•
•
Materi 1
Materi 2
Materi 3
Materi 4
Materi 5
3
12.1. Overview
•
Mudah untuk menentukan ukuran kesuksesan
dan kegagalan (menang atau kalah).
•
•
Perhatikan permainan Catur (chess).
Rata-rata setiap node bercang sebanyak 35.
Tiap pemain rata-rata bergerak 50 kali.
Sehingga total dalam satu pohon permainan
akan terdapat posisi sebanyak 35100.
Netoda-metoda yang digunakan dalam game :
•




Depth-limited search.
Statistic evaluation function.
Credit assignment problem.
Minimax search algorithm.
4
12.2. Prosedur pencarian MINIMAX
• One-Ply Search :
A
B
C
D
(8)
(3)
(-2)
• Two - Ply Search :
B
A
C
D
E
F
G
H
I
J
K
(9)
(-6)
(0)
(0)
(-2)
(-4)
(-3)
5
Prosedur pencarian MINIMAX
• Backing Up the Values of a Two-Ply Search
6
Algorithm : MINIMAX (Position,Depth, Player)
1. If DEEP-ENOUGH(Position, Depth), then return the
structure
VALUE = STATIC(Position, Player);
PATH = nil
This indicates that there is no path from this node and
that its value is determined by static evaluation function.
2. Otherwise,generate one more ply of the tree by calling
the function MOVEGEN(Position,Player) and setting
SUCCESORS to the list it returns.
3. If SUCCESORS is empty, then there are no moves to be
made, so return the structure that would have been
returned if DEEP-ENOUGH had returned true.
7
Algorithm contd’
4. If SUCCESORS is not empty, then examine each
element in turn and keep track of the best one. This is
done as follows. Initialize BEST-SCORE to the minimum
value that STATIC can return. It will be update to reflect
the best score that can be achieved by an element of
SUCCESORS. For each element SUCC of
SUCCESORS, do the following :
Set RESULT- SUCC to
MINIMAX(SUCC, Depht + 1, OPPOSITE(Player))
This recursive call to MINIMAX will actually carry out the
exploration of SUCC.
b) Set NEW-VALUE to - VALUE(RESULT-SUCC). This will cause
it to reflect the merits of the position from the opposite
perspective from that of the next lower level.
c) If NEW-VALUE > BEST-SCORE, then we found a succesor
that is better than any that have been examined so far. Record
this by doing the following :
a)
8
Algorithm contd’
• Set BEST-SCORE to NEW-VALUE.
• The best known path is now from CURRENT to SUCC and then on
to the appropriate path down from SUCC as determined by the
recursive call to MINIMAX. So set BEST-PATH to the result of
attaching SUCC to the front of PATH(RESULT-SUCC).
5. Now that all the succesors have been examined, we
know the value of Position as well as which path to take
from it. So return the structure
VALUE = BEST-SCORE
PATH = BEST-PATH
9
Prosedur pencarian MINIMAX
A
B
-6
C
-2
MAX
-2
D
-4
MIN
E
F
G
H
I
J
K
L
9
-6
0
1
0
-2
-4
-3
10
Prosedur pencarian MINIMAX
• Pada MINIMAX terdapat 2 prosedur yang
dijalankan yaitu : maximize dilakukan oleh “saya”
dan minimize dilakukan oleh “lawan”.
• Diperlukan fungsi evaluasi statis yang menyatakan
nilai yang mungkin didapat oelh pemain.
• Pada level pertama “saya” melakukan maximize
dan pada level kedua “lawan” melakukan
minimize.
• Kelemahan metoda MINIMAX adalah harus
mengunjungi semua node yang ada sebelum
memutuskan langkah yang diambil.
11
<< CLOSING >>
Untuk memperbaiki kelemahan metoda
MINIMAX digunakan
-Cutoff atau -pruning
End of Pertemuan 15
Good Luck
12