AI 五子棋

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 nameState modelscore
fiveAAAAA1000000
Good four?AAAA?90000
Bad fourAAAA?,?AAAA,A?AAA,AA?AA,AAA?A6000
Good three?AAA?5000
Bad three?AA?A?,?A?AA?3000
Good two?AA?1000
Bad twoAA?,?AA200
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.

modestepmethodcomplexityResponse time
mode 1Evaluation function<255<1s
mode 2Step1Minimax treeMore than 200^3 leaves>>1min
mode 2Step2α–β pruningAbout 10000 leavesAbout 30s
mode 2Step3Best 10at 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.

gitlab link

https://gitlab.com/hybill/Gomoku_ai.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值