What is Gomoku?
Gomoku is an abstract strategy board game. Also called Gobang or Five in a Row, it is
traditionally played with Go pieces (black and white stones) on a go board with 19x19 (15x15) intersections; however, because pieces are not moved or removed from the board, Gomoku may also be played as a paper and pencil game. This game is known in several countries under different names.
Evaluation function design
This is the most important part of this project. We need to evaluate each broad so that we can understand who is better. We need to give a score table for each state.
State name State model grade
State name | State model | score |
---|---|---|
five | AAAAA | 1000000 |
Good four | ?AAAA? | 90000 |
Bad four | AAAA?,?AAAA,A?AAA,AA?AA,AAA?A | 6000 |
Good three | ?AAA? | 5000 |
Bad three | ?AA?A?,?A?AA? | 3000 |
Good two | ?AA? | 1000 |
Bad two | AA?,?AA | 200 |
Good one | ?A? | 100 |
mode1-- AI just based on the evaluation function
The mode1 AI is basic but efficient AI. The AI will put chess in each empty space on the broad and give a grade for each possibility. The mode1 AI will return the choice with the highest grade.
mode2 --Adversarial Search
Step 1: we need to build a search tree and use the minimax decision to return a max value and position. If the depth=1, we have 225(15 *15) possibilities. If the depth = 2, we have 225 * 224 possibilities. If the depth = 3, we will have 225*223*222 possibilities. When the depth=3, the response time will be about 1 mins. We cannot wait so much time when playing Gomoku.
Step 2: We need to use the α–β pruning to improve the algorithm.
if depth == 0, return evaluation()
else while has empty space {
change broad // put chess on the empty space
val = AlphaBeta (depth-1,-beta,-alpha, broad,!isblack)
Back broad // take the last chess away
if val > beta, return beta
if val > alpha, alpha = val
} end while
end if return alpha
}
According to my test, after using the α–β pruning to improve the algorithm, we can cut half of
the possibilities. However, this method also needs to take a long time if the depth >3. So we need to improve the algorithm again.
Step 3: In each node of the tree, we have more than 220 branches. However, most of these branches are invaluable because these most of the places on board have no pieces around and these places are invaluable. So we need cut off these branches. At each branch, we scan the broad by the evaluation and get the best 10 valuable places so that each node has 10 branches.
Analysis
Now I have finished my AI search tree. We can compare the efficient in the following table. We
assume that depth = 3.
mode | step | method | complexity | Response time |
---|---|---|---|---|
mode 1 | Evaluation function | <255 | <1s | |
mode 2 | Step1 | Minimax tree | More than 200^3 leaves | >>1min |
mode 2 | Step2 | α–β pruning | About 10000 leaves | About 30s |
mode 2 | Step3 | Best 10 | at each node 1000 leaves | <3s |
We can find that the mode 2 has acceptable response time after 3 times improvement. However,the mode 2 is not perfect. Sometimes, the player has won in depth=2 but the AI give the best one in depth = 3. The evaluation function in the mode 2 is very difficult to design. The mode 1 just needs to consider the best choice but the evaluation function in the mode 2 need focus on analysis the board and get the report which player is better. Besides, most of the time we play
Gomoku like the mode 1. We try to find the best valuable places on board. However, the mode 2 can be extended.
I think that AlphaGo has similar AI system. I believe AlphaGo also need to use Minimax with α–β pruning and then exclude the invaluable places so that make the number of the leaves countable. It is difficult to design the evaluation function for AI. AlphaGo uses the machine learning make each step more valuable because we cannot cover all possibilities.