summary
This is a webpage to play Gomoku game with my AI.
Players take turns to place a stone of their color. The winner is the first player to form an unbroken chain of five stones horizontally, vertically, or diagonally.
This AI has nothing about machine learning. It abstracts the board into another space and calculates the value.
rule
Players take turns to place a stone of their color.
The winner is the first player to form an unbroken chain of five stones horizontally, vertically, or diagonally.
Visit wikipedia for more information.
operation
Click on the board to place a stone. Then wait for AI to move.
Player with black stone move first. You take black stone first, which means you moves first.
After some player wins, you will change the color of stone. That means, AI moves first in the second game.
algorithm
This AI has nothing about machine learning.
abstracts the board
This AI completely giveup the concept of "space". Instead of judging by coordinate, it is considering "chain to win". Each "chain to win" is 5 grids. If a player occupied the whole chain, then they wins.
When AI is considering about the benefit of placing a stone to a location, it considers all chains containing that location.
This location contains 7 chains.
For each chain, it calculates the attack value and defence value for adding a new stone to this chain.
The more ally stones are in this chain, the higher the attack value is, since it is easier to win by this chain. However, if one enemy stone appears, the attack value is 0 no matter how many ally stones exist, since it is impossible to win by this chain.
Conversely, the more enemy stones are in this chain, the higher the defence value is, since it is more possible to lose by this chain. However, if one ally stone appears, the defence value is 0 no matter how many enemy stones exist, since it is impossible to lose by this chain.
AI add attack value and defence value for all chains together, to get a total attack value and defence value. The raw value of this location will be the larger one.
consider one more step
Using the above algorithm, the AI might waste a lot of potential winnable chains too early.
Location 1 has higher attack value, but location 2 is a better move. That because your enemy usually block you immediately after the move 1, then some chain of win will lose a lot of value because of the single incoming enemy stone.
For each location, the AI will think in the place of enemy, trying to figure out the raw value in every location if the AI has already placed the stone. The AI will faigure out how much value it will lose if enemy places a stone right after the AI's move. The AI will also find out how certain the enemy player moves in that location, by compare the value of the location with the sum of the value on the board. Using these two index, the AI will estimate how much negative impact the enemy player will cause by their next move.
This causes AI to store a lof of potential winnable chains, and extend them together.
general knowledge
100% win chance
The first player to move has a 100% win chance, if they are smart enough. To be fair, the professional competition disabled some moves for the first moving player.
absolute defence
If you occupied some locations on the board, you will not lose.
source: https://gss0.baidu.com/-4o3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/b8014a90f603738db50edda7b51bb051f919eceb.jpg
The black player will never lose.