Starting from:
$35

$29

Project 1 AI Algorithm for Gomoku Solution

1 Description

Gomoku is a relatively simple board game. Its instrument is universal with Go, and it originated from one of the ancient Chinese black and white chess. Usually, the two sides use black and white chess pieces respectively, and at the intersection of the straight line and the horizontal line of the board, the next step is to form a five-member line to win.

In this assignment, we use the default board of size 15*15 board (administrators can modify the settings as needed). Students need to implement the AI algorithm of Gomoku according to the interface requirements and submit it to the system as required.

2 Evaluation Rule


The assessment is divided into 2 phases:

Usability testing: In this test, we will use some simple board test cases where students need to find the best place to drop. Only jobs that pass the usability test can pass.

Scoring stage: Students who pass the usability test can participate in the points game (积分赛). The specific competition rules are as follows: Students can submit their AI algorithm to the Gomoku battle platform (it is a successful submission if it passes the usability test). After a successful submission, select the player PK who ranks ahead of itself. The score is increased by 10 if it wins. The score remains unchanged if it is a tie. The score is reduced by 10 points if it loses. To avoid the first-hand advantage, each time the student should play against PK 2 innings with each one staring the game first. If they win twice, or win once and draw once, they win; if they win once and lose once, they draw; if they lose twice, or lose once and draw once, they lose.

The final score is given according to the points.

The following game gives an example of the battle between two AI algorithms. Of course, this example is very simple and is the simulation result of two random AI algorithms.










































The score list is as follows








































The Gomoku battle platform is still in the phase of developing internal tests, and there is still much room for improvement in all aspects. After the system is stable, we will open it to all students. At present, we are recruiting outstanding students to participate in development and testing. If you are interested in it, please send an email to zhaoy6@sustc.edu.cn
3 Code requirements

1、Python version: 3.6

2、Code template:

    1 import numpy as np

    2 import random

    3 import time

4

    5 COLOR_BLACK=-1

    6 COLOR_WHITE=1

    7 COLOR_NONE=0

    8 random.seed(0)

    9 #don't change the class name

    10 class AI(object):

    11 #chessboard_size, color, time_out passed from agent

    12 def __init__(self, chessboard_size, color, time_out):

    13 self.chessboard_size = chessboard_size

    14 #You are white or black

    15 self.color = color

    16 #the max time you should use, your algorithm's run time must not exceed the time limit.

    17 self.time_out = time_out

    18 # You need add your decision into your candidate_list. System will get the end of your candidate_list as your decision .

    19 self.candidate_list = []

20

    21 # If your are the first, this function will be used.

    22 def first_chess(self):

    23 assert self.color == COLOR_BLACK

    24 self.candidate_list.clear()

    25 #==================================================================

    26 #Here you can put your first piece
    27 #for example, you can put your piece on sun(天元)

    28 self.candidate_list.append((self.chessboard_size//2,self.chessboard_size//2))

    29 self.chessboard[self.candidate_list[-1][0], self.candidate_list[-1][0]] = self.color

30

    31 # The input is current chessboard.

    32 def go(self, chessboard):

    33 # Clear candidate_list

    34 self.candidate_list.clear()

    35 #==================================================================

    36 #To write your algorithm here

    37 #Here is the simplest sample:Random decision

    38 idx = np.where(chessboard == 0)

    39 idx = list(zip(idx[0], idx[1]))

    40 pos_idx = random.randint(0, len(idx)-1)

    41 new_pos = idx[pos_idx]

    42 #==============Find new pos========================================

    43 # Make sure that the position of your decision in chess board is empty.

    44 #If not, return error.

    45 assert chessboard[new_pos[0],new_pos[1]]==0

    46 #Add your decision into candidate_list, Records the chess board

    47 self.candidate_list.append(new_pos)

48


3、Time measurement

start = time.time()

… algorithm…

run_time = (time.time() - start)

More products