联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> javajava

日期:2018-11-28 10:40

CSE231 Fall 2018

Project 10: English Checkers

This assignment is worth 55 points (5.5% of the course grade) and must be completed and turned in before 11:59pm on

TUESDAY November 27, 2018.

Assignment Overview:

How to use a custom-built Python class. In this project you are going to write Python program that uses an Artificial

Intelligence (AI) module to play the game of Checkers against a human. The AI module and a couple of other functions are

is already written and you are going to use those in your program.

Assignment Background:

You will implement a classical board game called Checkers in Python using classes. Checkers is a group of strategy board

games for two players which involve diagonal moves of uniform game pieces and mandatory captures by jumping over

opponent pieces. The game is usually played on an 8x8 “checkered” board. For an 8x8 board, there are twelve black and

twelve white identical game pieces called Pawns (or Men).

Game Rules and Objective:

Checkers is played by two opponents, on opposite sides of the game board. One player has the black pieces; the other has the

white pieces. Players alternate turns. A player may not move an opponent's piece. A move consists of moving a piece

diagonally (forward from the player’s side) to an adjacent unoccupied square. If the adjacent square contains an opponent's

piece, and the square immediately beyond it is vacant, the piece may be captured (and removed from the game) by jumping

over it. Only the dark squares of the checkered board are used. A piece may move only diagonally into an unoccupied square.

Capturing is mandatory in most official rules. In almost all variants, the player without pieces remaining, or who cannot move

due to being blocked, loses the game.

Pawn/Man: Uncrowned pieces, i.e pawns, move one step diagonally forwards, and capture an opponent's piece by moving

two consecutive steps in the same line, jumping over the piece on the first step. Multiple enemy pieces can be captured in a

single turn provided this is done by successive jumps made by a single piece; the jumps do not need to be in the same line

and may "zigzag" (change diagonal direction). In English Checkers pawns can jump only forwards.

Kings: When a pawn reaches the kings row (also called crownhead, the farthest row forward), it becomes a king, and is

marked by placing an additional piece on top of the first pawn, and acquires additional powers including the ability to move

backwards and (in variants where they cannot already do so) capture backwards. Like pawns, a king can make successive

jumps in a single turn provided that each jump captures an enemy pawn or king. More details on this game can be found here:

https://en.wikipedia.org/wiki/Draughts

In fact, the best way to learn the rules is to play the game first hand, you can play the game here:

http://www.247checkers.com/

The checkers.py file, Board and Piece class:

The Board and Piece classes are defined in the checkers.py file. So you have all the tools already to be used in a game.

You will use this class to write your game logic. You must not modify this class. The first thing you need to do is to read

this file and understand each function and variables in both of the classes. There is also a main function that tests

different functionalities of Board and Piece objects. Read, run and see the main function outputs to understand how the

classes work.

The game play:

Unfortunately we don't have any nice user interface for the game. What you are going to implement is a text based command

line interface. When you start/run the game, it will look like this:

Developed by The Students Inc.

CSE231 Summer Semester 2018

Michigan State University

East Lansing, MI 48824, USA.

Pick a color:

First the game will ask for which color you are going to choose, then you type black or white. Once chosen yours and

opponent's color are fixed. In our case, black will always play the first move. In our case the pawns will be denoted by b

and w, the kings will be denoted by B and W (for black and white respectively). The board is composed of 8x8 “cells” and

initialized with 12 black and 12 white pieces (for 10x10 board there will be 20 black and 20 white pieces etc.). In the starting

position the pieces are placed on the first three rows closest to the players. This leaves two central rows empty. The whites

will be placed at the bottom rows and blacks on the top. The last white row will start from the bottom left corner and the

pieces will be placed by skipping every other cell. The rows on the board is numbered as a, b, c, ..., h and the

columns as 1, 2, 3, ..., 8 etc.

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | b | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | | | |

+---+---+---+---+---+---+---+---+

f | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

g | | w | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Figure 0: Initial board

If you run the program (proj10.py), the game will start as follows

Developed by The Students Inc.

CSE231 Summer Semester 2018

Michigan State University

East Lansing, MI 48824, USA.

Pick a color: white

You are 'white' and your opponent is 'black'.

Black always plays first.

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | b | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | | | |

+---+---+---+---+---+---+---+---+

f | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

g | | w | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 12

Thinking ...

black played ('c6', 'd7').

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | b | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | b | |

+---+---+---+---+---+---+---+---+

e | | | | | | | | |

+---+---+---+---+---+---+---+---+

f | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

g | | w | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 12

[white's turn] :>

In the above case, the human player chose to be white, so the AI picked black and played its first move ('c6','d7'). The

game waits on a prompt that reads [white's turn] :>.

Game Commands:

In order to play the game, there is a set of commands that you are going to use (i.e. type at the prompt) --

? exit: If you type exit on the prompt, the game will exit by showing the final outcome of the game, like this:

[white's turn] :> exit

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | b | | b | |

...

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 12

This game ends in a draw.

? pass: If you type pass, this will cause you to give up the game and admit defeat, no winning condition will be

checked.

[white's turn] :> pass

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | b | | b | |

...

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 12

white gave up! black is the winner!! yay!!!

? move x y: This command will move a piece from position x to y, where x and y are diagonal to each other. Each

position is denoted with a string board position like 'a2', 'c4' etc. Each pawn only can move forward diagonals.,

but kings can move either forward or backward diagonals.

[white's turn] :> move f7 e8

white played ('f7', 'e8').

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | b | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | b | |

+---+---+---+---+---+---+---+---+

e | | | | | | | | w |

+---+---+---+---+---+---+---+---+

f | w | | w | | w | | | |

+---+---+---+---+---+---+---+---+

g | | w | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 12

Invalid moves will trigger Exceptions accordingly –

[white's turn] :> move e8 c6

Error: Invalid move, please type 'hints' to get suggestions.

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

...

[white's turn] :> move f3 e3

Error: Invalid move, please type 'hints' to get suggestions.

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

...

[white's turn] :> move f3 d5

Error: Invalid move, please type 'hints' to get suggestions.

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

...

? jump x y: This command will cause a piece to jump from position x to y, where x and y are diagonals that are

one cell away. This command will be used to capture an opponent piece between the positions x and y.

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | | | w |

+---+---+---+---+---+---+---+---+

f | w | | w | | b | | | |

+---+---+---+---+---+---+---+---+

g | | w | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 11

[white's turn] :> jump g4 e6

white played ['g4', 'e6'].

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | w | | w |

+---+---+---+---+---+---+---+---+

f | w | | w | | | | | |

+---+---+---+---+---+---+---+---+

g | | w | | | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 11, White: 11

This command will also display similar message on the event of an invalid jump.

? hints: If you type this command it’s going to show the moves or jumps that you have on the board. If there are

jumps, no move is allowed and hints will show them accordingly.

[white's turn] :> hints

You have moves:

1: e6 --> d5

2: e6 --> d7

3: e8 --> d7

4: f1 --> e2

5: f3 --> e2

6: f3 --> e4

7: g6 --> f5

8: g6 --> f7

9: g8 --> f7

10: h3 --> g4

11: h5 --> g4

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | | | b | | b |

...

[white's turn] :> hints

You have captures:

1: ['g4', 'e6']

2: ['g6', 'e4']

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

...

? apply n: when you type hints, it’s going to show you the available m number of moves (or jumps) numbered from

1. If you type apply n then n-th move (or jump) from the hints will be applied to the board.

[white's turn] :> hints

You have captures:

1: ['g4', 'e6']

2: ['g6', 'e4']

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | | | w |

+---+---+---+---+---+---+---+---+

f | w | | w | | b | | | |

+---+---+---+---+---+---+---+---+

g | | w | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 12, White: 11

[white's turn] :> apply 1

white played ['g4', 'e6'].

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

b | b | | b | | | | b | |

+---+---+---+---+---+---+---+---+

c | | b | | b | | b | | b |

+---+---+---+---+---+---+---+---+

d | | | | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | w | | w |

+---+---+---+---+---+---+---+---+

f | w | | w | | | | | |

+---+---+---+---+---+---+---+---+

g | | w | | | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | w | | w | | w | |

+---+---+---+---+---+---+---+---+

Black: 11, White: 11

When the game finishes, the program will end the game by declaring the winner with the difference in the number of piece

count –

[white's turn] :> white played ('f1', 'e2').

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | | | | | | | b |

+---+---+---+---+---+---+---+---+

b | b | | | | | | b | |

+---+---+---+---+---+---+---+---+

c | | | | | | b | | |

+---+---+---+---+---+---+---+---+

d | B | | b | | | | | |

+---+---+---+---+---+---+---+---+

e | | w | | | | b | | |

+---+---+---+---+---+---+---+---+

f | | | | | | | | |

+---+---+---+---+---+---+---+---+

g | | | | | | | | |

+---+---+---+---+---+---+---+---+

h | B | | | | B | | | |

+---+---+---+---+---+---+---+---+

Black: 9, White: 1

Thinking ...

black played ['d1', 'f3'].

Current board:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | | | | | | | b |

+---+---+---+---+---+---+---+---+

b | b | | | | | | b | |

+---+---+---+---+---+---+---+---+

c | | | | | | b | | |

+---+---+---+---+---+---+---+---+

d | | | b | | | | | |

+---+---+---+---+---+---+---+---+

e | | | | | | b | | |

+---+---+---+---+---+---+---+---+

f | | | B | | | | | |

+---+---+---+---+---+---+---+---+

g | | | | | | | | |

+---+---+---+---+---+---+---+---+

h | B | | | | B | | | |

+---+---+---+---+---+---+---+---+

Black: 9, White: 0

'black' wins by 9! yay!!

Project Specifications – proj10.py and tools.py files:

You need to complete the functions in the proj10.py file (along with code and function headers and comments), where all

the game-play logic and mechanisms will emulate the steps described previously. The last function, game_play_ai() will

use all the functions to implement the game-play. This is the function that we are going to test.

Also, there is another file called tools.py which includes couple of difficult functions (finding all capturing paths, finding

single move/jump positions etc.) that have already written for you. You need to import this module and use those functions

accordingly in your implementation. The set of functions that you need to complete are as follows:

1. def indexify(position):

This function converts the letter-number position to row-column indices. The input position is a string like 'a1', 'h8' etc.

The tuple returned is based on a design that has (row, column) pairs that start at (0,0) in the upper left corner. For example,

for an 8x8 board:

if the input is 'a1' then it will return a tuple (0,0)

if the input is 'a2' then it will return a tuple (0,1)

.

.

if the input is 'e4' then it will return a tuple (4,3) and so on …

Hint: This function does not check if the input is a valid position. This function should not have more than a line or two.

Consider creating a mapping of letters to numbers with a dictionary. Also, the numeric positions start from 0, not 1.

2. def deindexify(row, col):

This function does the exact opposite of indexify(). In this case, the input is row and column values and it returns strings

like 'a1', ' h8' etc. For example, for an 8x8 board:

if the input is 0,0 then it will return a string 'a1'

if the input is 0,1 then it will return a string 'a2'

.

.

if the input is 4,3 then it will return a string 'e4' and so on …

Hint: This function does not check if the input is a valid position. This function should not have more than a line or two.

Consider creating a mapping of numbers to letters with a dictionary. Also, the numeric positions start from 0, not 1.

3. def initialize(board):

We provide this function. This function puts white and black pieces according to the checkers game positions. The black

pieces will be on the top three rows and the white pieces will be on the bottom three rows (for an 8x8 board). The first row

for the black pieces will be placed as a2, a4, a6, ... etc. and the next rows will be b1, b3, b5, ... etc. For the

white rows, the placement patterns will be opposite of those of blacks. This function must work for any even length board

size.

4. def count_pieces(board):

Counts the total number of black and white pieces currently on the board. The counts will be returned as a tuple where the

count of the black will come first. For example, if black count is 10 and white count is 15, then it will return a tuple of ints

(10,15).

5. def get_all_moves(board, color, is_sorted = False):

This function calls the get_moves(board, row, col, is_sorted = False) function (given in the tools.py

file) to get moves for all the colored pieces on the board indicated by the color variable (color is a string, either ‘black’

or ‘white’). This function returns a list of tuples where each tuple is a pair of string positions, e.g. ('a1','c3'). The

first item (i.e. 'a1') is the position of the current piece and the second item is the move that the piece at the first position can

make. A tuple ('a1','c3') means the piece of color color at position 'a1' can move to the position 'c3'. Obviously,

this function goes over each piece in the board and list all the moves as a list of tuple as described. If the is_sorted value

is True then the final list must be sorted alphabetically by the first item in each tuple, then sorted by the second item (default

sorting works). Note that this function returns “moves”, not “captures”—a different function returns “captures.” For example,

in the example board of Figure 1:

1 2 3 4 5 6 7 8

+---+---+---+---+---+---+---+---+

a | | | | | | | | W |

+---+---+---+---+---+---+---+---+

b | | | W | | W | | | |

+---+---+---+---+---+---+---+---+

c | | | | | | b | | b |

+---+---+---+---+---+---+---+---+

d | w | | w | | | | b | |

+---+---+---+---+---+---+---+---+

e | | | | b | | b | | w |

+---+---+---+---+---+---+---+---+

f | w | | w | | | | | |

+---+---+---+---+---+---+---+---+

g | | | | w | | w | | w |

+---+---+---+---+---+---+---+---+

h | w | | | | | | | |

+---+---+---+---+---+---+---+---+

Figure 1: An example board configuration

If we call get_all_moves(board, 'black', True), then this function will return this list of moves –

[('c6', 'd5'), ('e4', 'f5'), ('e6', 'f5'), ('e6', 'f7')]

In the example above, each move is collected by calling get_moves() function. For example, the last two moves (i.e.

('e6','f5') and ('e6','f7')) came from calling get_moves() at position e6, so get_moves(board, 4,

5, True) will return this list:

['f5', 'f7']

6. def apply_move(board, move):

This function applies a move on the board, the variable move is a tuple of two positions as described previously. For example,

if we want to apply the move ('e6', 'f5') as found from the get_moves() function on the same board, we call this

function as apply_move(board, ('e6', 'f5')). Then this function will move the piece from e6 to f5. Basically,

it takes a reference to the piece at e6 and places it at f5 and then removes the piece at e6. This function must raise an

exception if the movement is not valid. You can check the validity by verifying if the position at move[1] is already in the

list found from the get_moves() function. Also, if a movement yields a board position on the kings row, then the piece

will turn into a king (use the turn_king() function in the Piece class).

7. def sort_captures(all_captures,is_sorted=False):

We provide this function. If is_sorted flag is True then the final list will be sorted by the length of each sub-list and the sublists

with the same length will be sorted again with respect to the first item in corresponding the sub-list, alphabetically.

8. def get_all_captures(board, color, is_sorted = False):

This function goes over the whole board cell by cell and for each piece with the given color, this function finds the set of

captures that can be made by each piece and returns them in a list. This function calls the get_captures(board, row,

col, is_sorted = False) function given in the tools.py file. For a given position (row, col), the

get_captures() function returns a list of all possible capture paths starting at that (row, col) position. For example, if

we call get_captures(board, 5, 2, True) (piece 'w' at position f3 in the Figure 1) then we will get this list –

['f3', 'd5', 'b7']

This is a capture path. This means the piece 'w' at f3 can jump to d5 and then jump to b7 to capture two 'b' pieces.

Therefore, this function returns a list of lists of captures found from get_captures() function for each piece on the board.

For example, if there are 3 black pieces on the board and each of them has capture paths of length 2, then the final list returned

by get_all_captures() function will have a length of 3 * 2 = 6. For example, if we call this function on the board given

in the Figure 1, e.g. get_all_captures(board, 'white', True) then we will get this list:

[['f3', 'd5', 'b7']]

because in the whole board only the white piece at f3 can capture opponent’s pieces. Use the same is_sorted flag when

you call get_captures(). If the is_sorted flag is True then the final list will be sorted by the length of each sub-list

and the sub-lists with the same length will be sorted again with respect to the first item in corresponding the sub-list,

alphabetically—we provide the function sort_captures() to do this sorting.

9. def apply_capture(board, capture_path):

This function applies a capture on the board. The variable capture_path is a list of jump positions, that can be found from

the get_captures() function described previously. For example, if we want to apply a capture path like [‘f3’, ‘d5’,

‘b7’] on the board in the Figure 1, we call this function as apply_capture(board, [‘f3’, ‘d5’, ‘b7’]).

Then this function will move the piece from f3 to d5, then from d5 to b7. Also, during these consecutive movements, this

function will remove the opponent pieces from e4 and c6. This function must raise an exception if one of the jumping

positions is not valid. This can be easily checked against the list found by calling the get_jumps() function given in

tools.py. More specifically, if we imagine the capture_path as series of positions like [p1, p2, p3, …, pn-1,

pn], and if we are at a position pi, we will just check if the immediate next position pi+1 is in the list found from

get_jumps(board, rowpi, colpi, False) function call.

10. def get_hints(board, color, is_sorted = False):

This function returns hints on the next valid moves or jumps (captures). It returns a tuple of two lists for all pieces on the

board with given color – (list of all possible moves, list of all possible jumps). If there are

jumps, then the first list will be empty. Both can be empty lists if there is neither any move nor jump. For example, if we call

this function for the board given in the Figure 1 as get_hints(board, 'white', True), it will return this tuple –

([], [['f3', 'd5', 'b7']])

The first list is empty because white must not make any move except jumps since it has at least one jump.

11. def get_winner(board, is_sorted = False):

Gets the current winner. The winner is decided as follows:

(a) If black still has moves or captures but white does not, then black is the winner, returns 'black'. Irrespective of

the piece count.

(b) If white still has moves or captures but black does not, then white is the winner, returns 'white'. Irrespective of

the piece count.

(c) If (a) or (b) does not hold, then if there is only one black and one white piece on the board and if both are kings, then

returns 'draw'.

(d) If (a), (b) or (c) does not hold, returns 'black' if the total number of black pieces is more than that of white pieces

and vice-versa, otherwise returns 'draw'.

Use the count_pieces() and get_hints() function here, pass the is_sorted flag to get_hints().

11. def is_game_finished(board, is_sorted = False):

This function returns a Boolean True/False. A game is finished when either black or white has no moves/captures. Use

get_hints() function here. (This function can be done in a few lines, as few as 3 lines.)

12. def game_play_human():

This function implements the main game-play mechanism by stitching up all the functions that have been written so far. This

function is already completed but you need to follow this code to write another function called game_play_ai().

12. def game_play_ai():

You need to complete this function using the help from the game_play_human() function. In game_play_human()

both black and white moves are provided by a human. In this function, instead of getting all moves from a human, the human

provides moves for one color, but moves for the other color come from a call to the AI functions to get the next move. The

game AI is implemented in the gameai.py module.

How to use the AI module to get the next move?

In the gameai.py, module there is a function called get_next_move(board, turn), where turn is a color

string like 'black' or 'white'. Please open the gameai.py file and locate the function. Given a board and

a color, the get_next_move() will return the best move, like this:

move = gameai.get_next_move(board, turn)

The move can be either a move like ('e6','f5'’) or a jump sequence like ['f3', 'd5', 'b7']. The AI

module depends on the functions that you are going to write, the AI will not work if your project code is

incomplete. Specifically, the AI code depends on get_hints(), apply_move() and apply_capture()

functions.

Hint: only a few lines differ between the game_play_human() and the game_play_ai(). Basically, you need to

decide if you are prompting the human player for a move or, if it is the other color’s turn, calling the

gameai.get_next_move() function shown above to get the move. Because gameai.get_next_move() returns

either a move tuple or jump-sequence list, you will need to build an appropriate command (like the string provided by a

human). I copied the game_play_human() function and added 8 lines to create game_play_ai()

Important: before submission for testing you need to fix main to play the AI version rather than the human version.

More tips:

The file examples.py includes a set of example board configurations, use them to test the different edge cases for your

functions.

Deliverables:

The deliverable for this assignment is the following file:

proj10.py – the source code for your Python program

Be sure to use the specified file name and to submit it for grading via the Mimir system before the project deadline.

Sample game-play outputs and Mimir tests:

The mimir system will test all the functions specified in this project description. Mimir will also test a game-play example

specified in play.in by comparing them with the play.out. There is also a hidden test whose input/output will not be

provided to the students. You are strongly recommended to read the example game-play outputs in play.out file.

They can be opened with notepad/wordpad or text-editor on Mac.

Grading Rubric:

The most part of the project will be graded by mimir's automated tests and the score allocations are done as follows:

General Requirements:

( 3 pts) Coding standard 1-9, see the cse231 course web page.

Implementations:

( 4 pts) indexify() and deindexify() tests

( 3 pts) count_pieces() test

( 5 pts) get_all_moves() test

( 5 pts) apply_move() test, must throw RuntimeError

Two tests: one without exceptions; one with

( 4 pts) get_all_captures() test

( 7 pts) apply_capture() test, must throw a RuntimeError

( 3 pts) get_hints() test

( 5 pts) get_winner() test

( 3 pts) is_game_finished() test

( 8 pts) game_play_ai() test (test with play.in and play.out files)

( 5 pts) hidden Test


版权所有:留学生程序网 2020 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。