代做CS3243 Introduction to ArtificialIntelligence Project 3: Adversarial Search AY2024/2025 Semester 2

CS3243 Introduction to Artificial Intelligence

Project 3: Adversarial Search

AY2024/2025 Semester 2

Issued: 17 March 2025

Due: 13 April 2025, 2359hrs

1 Overview

In this project, you will implement an adversarial search algorithm to find valid and good moves for a modified chess game. Specifically, you are tasked to implement the Alpha-Beta Pruning algorithm to play a modified game of chess.

This project is worth 10% of your course grade, with an extra 2% bonus.

1.1 General Project Requirements

The general project requirements are as follows:

• Individual project: Discussion within a team is allowed, but no code should be shared

• Python Version: ≥ 3.12

• Deadline: 13 April 2025, 2359hrs

• Submission: Via Coursemology – for details, refer to the Coursemology Guide on Canvas

1.2 Academic Integrity and Late Submissions

Note that any material that does not originate from you (e.g., is taken from another source) should not be used directly. You should do up the solutions on your own. Failure to do so constitutes plagiarism. Sharing of code between individuals is also strictly not allowed. Students found plagiarising will be dealt with seriously.

For late submissions, there will be a 20% penalty for submissions received within 24 hours after the deadline, 50% penalty for submissions received between 24-48 hours after the deadline, and 100% penalty for submissions received after 48 hours after the deadline. For example, if you submit the project 30 hours after the deadline and obtain a score of 92%, a 50% penalty applies, and you will only be awarded 46%.

2 Background: Fairy Chess

Fairy chess is a modified chess game that includes pieces with nonstandard movements1 . In this project, you will be creating an agent that can find the best move for a given fairy chess board position. Your agent must be implemented using the Alpha-Beta pruning algorithm.

2.1 Rules of the Game

2.1.1 Board

For ease of implementation, we will not use standard chess board notation. Instead, squares on the chessboard will be represented as a Tuple[int,int], representing the row and column of the square. The top-most row is row 0, and the left-most column is column 0. An example chessboard is depicted in Figure 1 below.

Figure 1: Chess board with labelled squares

2.1.2 Movement of Chess Pieces

The classic chess pieces that will be used are as follows.

King: The king can move one square in any direction.

Rook: A rook can move any number of squares along a rank or file but cannot leap over other pieces.

Bishop: A bishop can move any number of squares diagonally but cannot leap over other pieces.

Knight: A knight moves in an “L”-shape, i.e., two squares vertically and one square horizontally, ortwo squares horizontally and one square vertically. Note that the knight can leap over other pieces.

In addition to the standard chess pieces mentioned above, two other fairy chess pieces will be defined.

• Squire: A squire can move to any square a Manhattan distance of 2 away. A squire can also leap over other pieces.

• Combatant: When moving (without capturing), the combatant moves one square orthogonally in any direction (denoted by points in Figure 2). When capturing, the combatant captures one square diagonally in any direction (denoted by crosses in Figure 2).

Figure 2: Chess piece movement

2.1.3 Winning Conditions

In this variant, the game is won by capturing your opponent’s King; it is lost when your King is captured. Note that this means the concepts of check, checkmate, and stalemate do not apply. An agent may (either accidentally or being forced to) put its own King under attack, and if a King is under attack, an agent is not forced to defend it. The game ends when any King is captured, hence, if both Kings are under attack, the player that captures the opponent King first wins.

With this modified winning condition, the concept of stalemate also does not apply. A stalemated King is forced to move into danger on the next move, resulting in a loss for the stalemated player.

2.1.4 Draws

A draw will be declared if only Kings are left on the board. The game is drawn even if one King can capture the other on the very next move.

2.2 Getting Started

You are given one python file (AB.py) with the recommended empty functions/classes to be implemented. Specifically, the following files are given.

1.studentAgent(gameboard): This function takes in a parameter gameboard and returns a move. More details on the output will be given in the later sections. DO NOT REMOVE THIS FUNCTION.

2.get_legal_moves(gameboard,color): This function takes in two parameters, gameboard and color. This function should return a list of moves. DO NOT REMOVE THIS FUNCTION.

3.ab(): Implement the Alpha-Beta Pruning algorithm here. (You may change/remove this function, as long as you keep the studentAgent(gameboard) function and return the required value(s).)

4.State: A classstoring information of the game state. (You may change/remove thisfunction as desired, as long as you keep the studentAgent(gameboard) function and return the required value(s).)

5.Board: A class storing information of the board. (You may change/remove this function as desired, as long as you keep the studentAgent(gameboard) function and return the required value(s).)

6.Piece: A class storing information of a game piece. (You may change/remove this function as desired, as long as you keep the studentAgent(gameboard) function and return the required value(s).)

You are encouraged to write other helper functions to aid you in implementing the algorithms. Do note that during testing, the Autograder will call both studentAgent(gameboard) and get_legal_moves(gameboard,color).

2.3 Winning a Fairy Chess Game Using Alpha-Beta Pruning

The objectives of this project are as follows.

1. To gain exposure in the implementation of the algorithms taught in class.

2. To learn how to apply the Minimax algorithm to games.

3. To learn the efficiency and importance of using Alpha-Beta Pruning.

3 Project 3 Task 1

Many years have passed since the last invasion and the people of CS3243 kingdom are living peacefully and happily. However, the council of CS3243 Kingdom detects an imminent threat from our enemy Kingdom, CS9999 and are fearful that a war may break out soon. In order to prepare for the war, the council seeks to recruit a strategic advisor. To assess the best candidate, the council decides to organise a fairy chess competition that anyone can join. The participants will compete against AI agents of various difficulty levels and the participant that wins against all the AI agents will be recruited as the strategic advisor. Being an avid fairy chess player in the kingdom, you decide to join the competition to challenge yourself!

3.1 Task 1: Alpha-Beta Pruning Algorithm

Implement the Alpha-Beta pruning algorithm to find the best move for a given fairy chess board state.

3.1.1 Input

The function studentAgent() takes in a parameter gameboard that is a list of all the pieces on the board. Each piece is represented by a tuple containing 3 elements. The first element is a string containing the name of the piece. The second element is either the string ’white’ or ’black’, and this element represents the colour of the piece. The last element is another tuple, representing the position of the piece using the notation defined in Figure 1. An example of the gameboard is given below.

[(′King′,′white′,(7, 0)), (′King′,′black′,(0, 7)), (′Knight′,′white′,(3, 4))]

3.1.2 Output

When the studentAgent() function is executed, your code should return a valid move in the following format.

(pos1, pos2)

To be more precise, your studentAgent() function should return a tuple containing two other tuples. The first tuple represents the starting position of the piece you intend to move. The second tuple represents the position you intend to move the piece to. Both positions are denoted using the notation in Figure 1. Note that captures are not denoted differently from other moves, if pos2 is occupied by an opponent piece, it is guaranteed that the piece at pos2 is captured after the move.

In addition, you are tasked to define a get_legal_moves(gameboard,color) function. This function should take in a gameboard as described above, and the string ’black’ or ’white’. This function should return a list all the legal moves available to the player whose colour is specified. An example is shown below.

Assume that the following is executed.

gameboard = [ (′King′,′white′,(7, 0)),

                       (′King′,′black′,(0, 7)),

                       (′Knight′,′white′,(3, 4)) ]

print(get_legal_moves(gameboard,’white’))

print(studentAgent(gameboard))

Consequently, the sample output representing your Knight at (3,4) moving to (5,5) is as follows.

# output of get_legal_moves:

[ ((7,0),(7,1)), ((7,0),(6,0)), ((7,0),(6,1)), ((3,4),(5,5)),

   ((3,4),(4,6)), ((3,4),(1,5)), ((3,4),(2,6)), ((3,4),(5,3)),

   ((3,4),(4,2)), ((3,4),(1,3)), ((3,4),(2,2)) ]

# output of studentAgent:

( (3,4),(5,5) )

3.1.3 Assumptions

In your implementation, you may assume the following.

• Both players will have a King on the board.

• With the exception of the first four test cases (where the get_legal_moves function is evaluated), every other test case is a board position such that one move is clearly better than all other moves (i.e., only one move leads to a forced win or leads to winning material2 ).

• In the board position given, you will only play as “white”.

You may assume that the opponent plays optimally.

3.2 Grading (Total: 10 marks + 2 bonus marks)

3.2.1 Evaluating Your Agent

Your agent will not be playing a game. Instead, your agent will be tasked to find the best move for several given board positions. However, do feel free to let your agent play against itself to view the performance of your agent in a real game.

The test cases will test for the following:

• Test cases b1 - b4: Find all the legal moves for a given board position.

• Test cases m1_1 - m1_2: Find the best move for a board position where there is a forced win in one move (i.e., you may capture the black King in one move).

• Test cases m3_1 - m3_4: Find the best move for a board position where there is a forced win in three moves (i.e., two moves by white, one move by black).

• Test cases m5_1 - m5_4: Find the best move in a board position where there is a forced win in five moves (i.e., three moves by white, two moves by black).

• Test cases e3_1 - e3_2: Find the best move in a board position where there is a guaranteed way to win material in three moves.

• Test cases e5_1 - e5_4: Find the best move in a board position where there is a guaranteed way to win material in five moves.

• Bonus test cases e5_5 - e5_6: Find the best move in a board position where there is a guaranteed way to win material in five moves (note: these are very tricky test cases).

3.2.2 Marks Distribution

The grading rubrics are as follows:

• Test cases b1 - b4 (to test the get_legal_moves function): 0.5m each [total: 2m]

• Test cases m1_1 - e5_4: 0.5m each [total: 8m]

• Bonus test cases e5_5 - e5_6: 1m each [total bonus: 2m]

4 Submission

4.1 Details for Submission via Coursemology

Refer to Canvas > CS3243 > Files > Projects > Coursemology_guide.pdf for submission details.

5 Appendix

5.1 Allowed Libraries

The following libraries are allowed:

• Data structures: queue, collections, heapq, array, copy, enum, string

• Math: numbers, math, decimal, fractions, random, numpy

• Functional: itertools, functools, operators

• Types: types, typing

5.2 Tips and Hints

• IMPORTANT: Do not spend too much time optimising the heuristic! A simple weighted sum of piece values is sufficient. Evaluation of more complicated heuristics may slow down your code significantly due to the frequency with which the evaluation function is called. You may search online to determine how to define a good evaluation function.

• With an average computer, you may expect the slowest test cases to run in under 2 seconds (locally).

• ChatGPT is quite useful for generating the skeletal code for minimax, as well as the piece movements. You may use that as a starting point. For Project 3, you are allowed to use ChatGPT to assist you.




热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图