Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS4386 Assignment 1

1 Game Rules

There are two players in this game. In each turn, a player can put a chessman in the specified empty cell of the 6*6 board (player 1 is only allowed to put it in the black box, and player 2 is only allowed to put it in the white box). Any player who can connect 3 or 6 adjacent chessman (color does not matter) in a row/column (no diagonal) will get 3 or 6 points respectively. The game ends when all the cells are taken by players and the player who gets higher points is the winner.

 

Case 1-4 illustrate the rules of this game (Player 1 is denoted by green and Player 2 is denoted by red).


Case 1:


Step i

Step i+1

 

 

 

 

In this case, player 1 will get 3 points in step i+1 since he connects 3 adjacent chessman.


Case 2:


Step i

Step i+1

 

 

 

 

In this case, player 2 will get 6 points in step i+1 since he connects 6 adjacent chessman.


Case 3:


Step i

Step i+1

 

 

 

 

In this case, player 1 will get 3+3=6 points in step i+1 since he connects 3 adjacent chessman both in row and column.

Case 4:

In each turn, a player can put a chessman in the specified empty cell of the 6*6 board (player 1 is only allowed to put it in the black box, and player 2 is only allowed to put it in the white box). If the player puts the chessman in the wrong cell, he will lose the game.

In this case, player 1 wants to put it in white cell. It is an illegal move, so he lose the game.

2 Demo codes

Github Link:https://github.com/zwebzone/CS4386_A1_forALL

Same code can be also found in Canvas (Files > Assignment1>CS4386_A1_forALL.zip)

Note: We will keep improving the demo codes and release the updated ones on Github, which will not be much different from this version. Hence, you can start implementing your AI based on this version now. Meanwhile, if you find any bugs in our demo codes, you can ask questions on Github issues and we will fix them.

How to Run

To run the demo codes, you need to install python3.6 first. The environment tutorial can refer to Appendix: Environment Tutorial (the last two pages).

We support 3 languages for implement your AI: C++, JAVA and Python. Python is the easiest one to implement since our server program is written in Python. Hence, we highly recommend you to use Python. If you are not familiar with Python, you can use Java or C++.


Mode1 Human VS AI


1.   If your AI is implemented by C++:

cd cpp

g++ AIPlayer.cpp -fPIC -shared -o aiplayer.so

cd ..

#if you want the Human play first, use

python3 game.py Human CPP 1

#if you want the AI play first, use:

python3 game.py Human CPP 2

2.   If your AI is implemented by Java:

cd java

javac AIPlayer.java

mkdir com

mv AIPlayer.class com

jar cvf AIPlayer.jar com

cd ..

python3 game.py Human JAVA 1

3.   If your AI is implemented by Python:

python3 game.py Human PYTHON 1

Mode2 AI vs AI

#if you want the JAVA AI play with PYTHON AI

python3 game.py JAVA PYTHON 1

#if you want the PYTHON AI play with PYTHON AI

python3 game.py PYTHON PYTHON 1

How to implement your AI algorithm

Take the python version for example, you need to modify the get_move() function in AIPlayer.py.

def get_move(self, state, player):

# implement your algorithm here

games = self.available_cells(state,player)

random_move=random.choice(games)

#the end of your algorithm

return random_move

The example returns a random move, and you should modify it using your own algorithm. If your AI fails to return a move in a long time (e.g. 10 seconds per turn), your opponent will win the game.

You can define your own variables and functions in the AIPlayer Class, but you cannot delete existing variables or functions in AIPlayer Class. Meanwhile, you cannot change the function parameters of get_move() fuction. Note: When implement your AI, you MUST NOT change game.py or gui.py.

3 Scoring Scheme and Requirements

Total (20 scores) = Performance of your AI + codes + report

Note: Performance of your AI = whether you win the game (10 points for winner and 0 for loser) + your obtained points. In addition to the points you win against others, we will also grade you based on the quality of your algorithm.

1.   Requirement for the codes:

    At the beginning of your file (AIPlayer.cpp or AIPlayer.java or AIPlayer.py), add the following

comments to your code: (replace / to # in python code)

///////////////////////////////////

// CS4386 Semester B, 2022-2023

// Assignment 1

// Name: [Your name]

// Student ID: [Your student ID]

///////////////////////////////////

    You only need to submit the folder for the language of your choice and directly zip it to

a .zip file. We put a submission example in Canvas for your reference.

 

     Rename the zip file that contains the related files of your AI codes as

CS4386_2223B_[studentID].zip, where [studentID] is your student ID. You need to submit this zip file to Canvas.

2.   Requirement for the report:

    You should write a report to explain your AI.

    At the beginning of the report, include the following information:

o The heading CS4386 Assignment 1 (Semester B, 2022-2023)”

o Your name

o Your student ID

    You should then describe your algorithm as clearly as possible. Feel free to use examples

and add screenshots or other figures if it can help better illustrate your method.

     If you adopt some part of your code from somewhere, you must fully acknowledge

this and provide a reference to where you obtain the code. You must declare how  much of your submitted code is obtained from someone/somewhere else and how much is indeed written by you.

    At the end of your report, include the related references from where you have gathered

useful information in working on your assignment

    Convert your report to a PDF file with the file name CS4386_2223B_[studentID].pdf,

where [studentID] is your student ID.

    You need to submit this report together with your source code to Canvas.

3.   Submission

Submit both CS4386_2223B_[studentID].zip and CS4386_2223B_[studentID].pdf to canvas.

4 Q&A

We have created a discussion on CANVAS. You can ask questions there and the TAs will check it everyday and answer your questions as soon as possible.

 

5 Deadline

The DDL for this assignment is 17th  March.

Appendix: Environment Tutorial

We suggest you to use anaconda to run this assignment. And here are 4 steps for you to run Assignment2.

Step1 install anaconda

You can download anaconda3 fromhttps://repo.anaconda.com/archive/                 Anaconda3-5.2.0 contains Python3.6 and we suggest you to download this version.

In the following, we take the windows users for example since the case is more complex compared with  Linux/MacOS  users.  For  windows  users,  you  can  download  Anaconda3-5.2.0-Windows -

x86_64.exe.

 

After downloading it, you can install anaconda3 by double clicking the .exe file and remember the installation path (you can refer to https://zhuanlan.zhihu.com/p/61639212). After installation, you

need to check that your environment path contains the path of anaconda.

Then you can open the anaconda prompt:

 

You can use the following command to see the version of anaconda3:

conda --version

 

Step2 create env

You need to create an environment for running this assignment. The command is:

conda create -n cs4386 python=3.6

 

Then you can activate this env by:

conda activate cs4386

 

Step3 install packages

To install jpype1: pip3 install jpype1

 

Same to install pygame: pip3 install pygame

Step4 run A1

You can use the provided commands to run this assignment: python3 game.py Human PYTHON 1