PEMBUATAN GAME NIM MENGGUNAKAN
ALPHA-BETA PRUNING
ByMuhammad Arifin (7407 0300 45)
Supervisor :1. Entin Martiana Kusumaningtyas, S.Kom, M.Kom
2. Kholid Fathoni, S.Kom
Final Project Presentation
EEPIS-ITS, 2010
BACKGROUND
In 1950 the scientists and researchers think about how that machine can do the job as can be done by humans.
Definition of Artificial Intelligence (AI)“Artificial Intelligence is a study of how to make computers do things which at present can be done better by humans.” Rich and Knight [1991] .
AI Methods :Graph, Tree, Expert System, Game Playing, dll.
BACKGROUND
Minimax ConceptJohn von Neumann in 1944, describes a search algorithm in the game, known as the Minimax, which maximizes the player's position and minimize the opponent's position
Alpha-beta Pruning Concept- Alpa-beta Pruning is an improvisation from Minimax.- Basic Idea
“If you have an idea that is surely bad, don’t take the time to see how truly awful it is.” (Pat Winston)
OBJECTIVE
This project purpose is to make intelligent machine that can play Game NIM against Human, using the Alpha-beta PruningMethod.
PROBLEMS LIMITATION
NIM Game was built using JAVA programming language.
The variant of NIM Game that used in these project is type Grundy's game
Number of objects in NIM Game is dynamic between 5 s/d 15 objects
GAME THEORY
The general characteristics of the game : Have two player Perfect information game The player knows all the information state of the
game The loss of a player is a benefit to other players Does not contain probabilistic like dice
NIM GAME THEORY
Begins with a single heap of objects Each player must be able to split a heap of
objects into two heaps of different sizes. The number of object in each heap must not be
the same and cannot be empty. The game ends when only heaps of size two
and smaller remain, none of which can be split unequally.
The last player who can make an allowed move wins
NIM GAME THEORY
A normal play game starting with a single heap of 5 object : Player 1 has two choices, splitting 5 int, 4-1 or 3-2 Player 1 : 5 4-1 Player 2 only has one choices, splitting 4-1 into 3-1-1 Player 1 : 3-1-1 2-1-1-1 Player 2 has no move left and and loses.
NIM GAME THEORY
NIM Game can be implemented in program using tree theory
If we implemented all possible move in NIM Game with a single of 5 the we will have tree like these :
ARTIFICIAL INTELLIGENCE (AI)
Intelligence was created and inserted into a machine (computer) in order to do a job like that can be human.
An example of AI : Gary Kasparov vs Deep Blue in a match of Chess game
ARTIFICIAL INTELLIGENCE (AI)
Job’s that can be done by AI : Natural LanguageGame Robot Control And many other
ALPHA-BETA PRUNING
Alpha-beta pruning is a procedure to reduce the amount of computation and searching during minimax.
Rules for Alpha-beta Pruning- Alpha Cut-off : Search can be stopped below any MIN node having
a beta value less than or equal to the alpha value of any of its MAX ancestors.
- Beta Cut-off : Search can be stopped below any MAX node having a alpha value greater than or equal to the beta value of any of its MIN ancestors.
Evalution Function :- 0 MAX / alpha (Computer Win)- 1 MIN / beta (Player Win)
ALPHA-BETA PRUNING
For example number of objects is 6 and will generate all possible path in tree of NIM Game
Computer first turn.
6
5-1 4-2
4-1-1 3-2-1
3-1-1-1
2-1-1-1-1
2-2-1-1
3-2-1
2-2-1-1
6
7
5
4
3
2 8
9
10
1
ALPHA-BETA PRUNING
Searching start from the last state
6
5-1 4-2
4-1-1 3-2-1
3-1-1-1
2-1-1-1-1
2-2-1-1
3-2-1
2-2-1-1
MAXDepth = 0
6
7
5
4
3
2 8
9
10
MINDepth = 1
MAXDepth = 2
MINDepth = 3
MAXDepth = 4
1= Komputer (AI) Menang
= Player Menang
Alpha = 0
ALPHA-BETA PRUNING
6
5-1 4-2
4-1-1 3-2-1
3-1-1-1
2-1-1-1-1
2-2-1-1
3-2-1
2-2-1-1
MAXDepth = 0
6
7
5
4
3
2 8
9
10
MINDepth = 1
MAXDepth = 2
MINDepth = 3
MAXDepth = 4
1= Komputer (AI) Menang
= Player Menang
alpha = 0
beta = 0
alpha = 0
beta = 0
ALPHA-BETA PRUNING
Process of Beta Cut-off
6
5-1 4-2
4-1-1 3-2-1
3-1-1-1
2-1-1-1-1
2-2-1-1
3-2-1
2-2-1-1
MAXDepth = 0
6
7
5
4
3
2 8
9
10
MINDepth = 1
MAXDepth = 2
MINDepth = 3
MAXDepth = 4
1= Komputer (AI) Menang
= Player Menang
alpha = 0
beta = 0
alpha = 0
beta = 0
Pemangkasan Beta
ALPHA-BETA PRUNING
Last Process of Alpha-beta Pruning
6
5-1 4-2
4-1-1 3-2-1
3-1-1-1
2-1-1-1-1
2-2-1-1
3-2-1
2-2-1-1
MAXDepth = 0
6
7
5
4
3
2 8
9
10
MINDepth = 1
MAXDepth = 2
MINDepth = 3
MAXDepth = 4
1= Komputer (AI) Menang
= Player Menang
alpha = 0
beta = 0
alpha = 0
beta = 0
Pemangkasan Beta
beta = 1
beta = 1
alpha = 1
ALPHA-BETA PRUNING
To make decision Komputer (AI) will search for maksimum of evaluation function.
6
5-1 4-2
4-1-1 3-2-1
3-1-1-1
2-1-1-1-1
2-2-1-1
3-2-1
2-2-1-1
MAXDepth = 0
6
7
5
4
3
2 8
9
10
MINDepth = 1
MAXDepth = 2
MINDepth = 3
MAXDepth = 4
1= Komputer (AI) Menang
= Player Menang
alpha = 0
beta = 0
alpha = 0
beta = 0
beta = 1
beta = 1
alpha = 1 The best move
SYSTEM DESIGN
Menu permainan
User memilih jumlah batang NIM untuk dimainkan
User memilih siapa yang bergerak pertama
Permainan dimulai
Komputer melakukan proses Alpha-beta Pruning
Permainan berakhir sampai jumlah batang tidak dapat dipisahkan
Keluar
User mengaktifkan aplikasi
Back tomain menu
Permainan dilakukan hingga 3 Ronde
PLAYING TEST
Playing test will use the data from Game Configuration interface
Game Configuration:- Number of Object: 7- Game Mode: VS Computer- First Turn: Player- With Alpha-beta Pruning
PLAYING TEST
7 objects shown in the board as the game configuration ask for 7 objects.
The first turn is Player
PLAYING TEST
Why Computer (AI) chose to split 6-1 into 4-2-1 ? A single heap of 6-1 have 2 childs.
7
5-26-1 4-3
5-1-1 4-2-1
4-1-1-1 3-2-1-1
3-1-1-1-1
2-1-1-1-1-1
2-2-1-1-1
3-2-1-1
2-2-1-1-1
4-2-1 3-2-2
3-2-1-1
2-2-1-1-1
2-2-2-1
3-3-1
3-2-1-1 3-2-1-1
2-2-1-1-1 2-2-1-1-1
4-2-1
3-2-1-1
2-2-1-1-1
ComputerMAX
PlayerMIN
Alpha = 0
Beta = 0
Alpha = 1
ComputerMAX
PlayerMIN
ComputerMAX
PlayerMIN
= Komputer Menang
= Player Menang
Alpha = 0
Beta = 0
Beta = 1
Alpha = 1
Beta = 1
Beta Cut-off
Computer Position
PLAYER TURN
Computer movement :- Computer will always move according to the
maximum value of the Childs- If the Childs consist two of more same maximum
value the Computer will use random move of the same value.
PLAYING TEST
Player turn Player chose to split 4-2-1 into 3-2-1-1. The game board change into four heap, 3-2-1-1
PLAYING TEST
And Computer won the game because Computer is the last player who can make an allowed move
The games will be played as many as three rounds.
Most winners will win the game.
ANALYSIS
We will compare with Minimax method starting 7 to 15 objects. Whether the Alpha-beta pruning can to reduce the amount of computation and searching during minimax ?
And the result is :Jumlah
BatangJumlah Node
Jumlah Node yang Di lewati
Minimax Alpha-beta Pruning
7 26 22 15
8 58 54 36
9 176 171 76
10 470 465 112
11 1.687 1.681 353
12 5.595 5.589 635
13 22.178 22.171 1.389
14 82.370 82.363 3.427
15 372.074 372.066 10.671
CONCLUSION
Human can play the NIM Game with Computer using Alpha-beta Pruning method.
The Alpha-beta pruning method is an improvisation of Minimax method in the search nodes.