├── main.py
├── Menu.py
├── Rule.py
├── utils.py
├── Opago
│ ├── dataset
│ │ ├── 00000.npz
│ │ ├── ***
│ │ └── 03983.npz
│ ├── model
│ │ └── model_27.pth
│ ├── pre_dataset
│ │ ├── Renju1
│ │ ├── Renju2
│ │ └── Renju3
│ ├── cnn_utils.py
│ ├── create_dataset.py
│ ├── dataloader.py
│ ├── SimpleNet.py
│ └── train.py
├── image
│ ├── board.jpg
│ ├── black.png
│ └── white.png
├── making_board.ipynb
python 3.9
pytorch 1.12
- This project constructs an Opago (오목 모델, Gomoku AI model) AI with the pygame module in Python
- A convolutional neural network (CNN) is used
- The model structure is very simple and the hyperparameters are already tuned
- Input : (batchsize, 1, 15, 15) image
- Output : (batchsize, 225) array (The place where the next stone should be placed has value 1, and 0 for others 224 values)
# see how output of the Dataset looks like
print(torch.reshape(output[0].int(),(15,15)))
- Sigmoid function is used only at the last layer to get the biggest value among 255 values
- The reason why sigmoid function is used is to make every value to between 0 to 1 and it is ideal that letting the target index's value be close to 1 through training
- The index with the biggest value means the place where the next stone should be placed
- The dataset is from https://gomocup.org/results/
- Input: an image from during a play
- Output: 255 size array, set value 1 at the place where the next stone is placed after the input image and value 0 for others
- We can get a lot of data from just one game
- There is tremendous data available on that aforementioned website, which is organized by year
- This project itself uses game data from the years 2021, 2020 and 2019
- Coordinate information from the website above
- Renju is one of the names that refer to a way of playing Gomoku with specific rules (which are also the most popular)
- Change coordinate information to numpy 15 * 15 arrays and save them as
.npz
files in the dataset folder in order to be used as input to the CNN network
- Train Opago AI model using the CNN method.
- The input size is
(batchsize, 1, 15, 15)
, the output size is(batchsize, 255)
- To obtain a probabilty estimation, we use the sigmoid function as the activation function in the last layer with a 255 size array
- We can augment the data by eight times by flipping (up, down,left, right) and rotating (90, 180, 270, 360 degrees) since the board is symmetric
- Checking whether the total game is over or not by counting the number of wins whether it exceeds two times
- Also, showing message if the game is over
- Checking whether the game is over or not with an algorithm that is checking that there are 5 stones in arrow
- There are various functions necessary to visualize the game from drawing the stone on a board to letting the AI get a point to win a game
- If the whole game is over, then quit the game
- Making a board image with a cv2 and PIL module
- Use a 15*15 grid board
- Randomly assign the black and white player
- Black always begins
- The black player's first stone must be placed in the center of the board
- If any player wins twice, the whole game is over
- Blocking samsam which is the strategy that black cannot use is not implemented yet
- The second black stone cannot be placed inside 5x5 center area (since Black should be penalized for being able to place the first stone)
- Gomoku with Pygame module (https://m.blog.naver.com/dnpc7848/221503651970)
- Create dataset for CNN network from coordinate to array (https://github.com/kairess/omok-ai)