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

Assignment #2

Summary of Assignment

Consider the assignment below and develop an algorithm to solve it based on the information provided.

This Assignment must be completed in groups of two to three students. No groups larger than three students will be permitted. Following page may help you to create groups:

https://www.sfu.ca/canvas/instructors/course-admin/create-a-group.html (https://www.sfu.ca/canvas/instructors/course- admin/create-a-group.html) (https://www.sfu.ca/canvas/instructors/course-admin/create-a-group.html)

Please note this assignment will be graded using grading software that runs your code. if your code does not compile or does not produce the correct output the maximum score you will receive is 20%.

Your code will play a game called Cylindrical Mule Checkers (CMCheckers). CMCheckers is a game

similar to Checkers. The rules for this game are a little different from Checkers so please read the rules below carefully.

The CMCheckers.cpp file should contain the solution for the assignment. In particular, the CMCheckers.cpp file should contain:

1.  main() function

2.  InitializeBoard  function

3.  DisplayBoard function

4.  CountJumps function

5.  CountMove1Squares function

6.  IsMove1Square function

7.  Checklist function

8.  IsJump function

9.  MakeMove function

10.  CheckWin function

These functions must have the exact prototypes given at the start of the description of part a of the  assignment and must be used in your code. For each function whose prototype you change you will automatically lose 5 marks of the 100 marks for the assignment.

You will need to develop and implement an algorithm to solve the problem. Include the common case

and most special cases in the algorithm and implementation. You must implement all special cases

including those special cases that involve inputs of incorrect data type.  Put your implemented program in a file CMCheckers.cpp.

The Game of CMCheckers is a strategy oriented board game with the following rules:

1. The game begins on a board of N squares by N squares.  8<=N<=18. N is even.

2. The game is played by two players using checkers that are placed on the squares of the board. One player uses red checkers; the other player uses white checkers.

3. There are three types of checker, two of which are placed on the initial board.  Mules and Soldiers are placed on the initial board.  Soldiers and Mules can become kings later in the game.

4. White moves rst.

5. The initial board will be set up as shown below.  The circular pieces are soldiers, the horsehead shape pieces are mules.  Soldiers and mules are moved in exactly the same ways.  To determine who wins the  game the difference between soldiers and mules is important.  How you win the game will be discussed   later.

6. A player may move a checker diagonally one space forward (towards the opponent, away from the   player). A checker may be moved only onto a board square that is empty. Moves work as if the board   was cylindrical.  Imagine that the right hand side of the board connects to the left hand side to form a   cylinder.  This means you can move off the right hand side of the board onto the left hand side of the    board and move off the left hand side of the board onto the right hand side of the board as on the right shown below:

7. A player may also move a checker by jumping. You can jump when one of your opponent’s checkers is in front of one of your checkers along a diagonal.  The space along the diagonal beyond your opponent’s piece must be empty.  An example is shown below.  After you have jumped your opponent’s checker,

your opponents checker is removed from the board.

After jumping an opponent’s piece your checker may have another jump available from its new position.  A checker can jump any number of times in a single turn.

8. If one or more of a player’s checkers can make a jump, that player must make a jump. If more jumps are available with that same checker, the player must

If more than one of a player’s checkers has a jump available at the start of that player’s turn, that player may choose which of the checkers that could jump to move. The player must make all the jumps

available for that checker. If one of a player’s checkers can make more than one possible jump from a particular square on the board then the player may choose which jump to make

9. When one of a player’s checkers reaches to opponent’s side of the board it is crowned and becomes a king. The player’s turn ends when a checker is crowned.

10.   A king can move and jump both forward and backward.  Other rules for moving and jumping are the same as for other checkers.

11.   A game ends when

· A player has no possible moves (the player with no moves loses).

· A player has captured and removed all of his opponent’s checkers that are not mules from the board. The player with only mules on the board loses.

· A player loses all her mules.  The player who lost all her mules wins.

· A mule becomes a king. The player whose mule becomes a king loses.

IMAGES AND SOME RULES ARE FROM OR ARE ADAPTED FROM

https://www.itsyourturn.com/t_helptopic2030.html#helpitem1197

(https://www.itsyourturn.com/t_helptopic2030.html#helpitem1197)

To implement your version of CMCheckers you will write a main program and the following functions. The main program and the functions will be written inside a file called CMCheckers.cpp. You must use the

exact prototypes given as we may test your functions without your main program. You may use additional function if you wish. The prototypes of your functions are given below. The purpose of each of the

functions is explained after the description of the main program.

Do not declare the cmcheckersboard array as a global variable.

Do not declare the mycmcheckersboard array as a global variable.

Do not use global variables (global constants are ok).

Your main program should

1.   Declare an array myCMCheckersBoard[MAX_ARRAY_SIZE][MAX_ARRAY_SIZE] as a local

automatic variable in the main program. MAX_ARRAY_SIZE should be a declared constant with global scope and with a value 18.

2.   Declare 2 arrays of xIndicesMove[] andyIndicesMove[]. Each of these arrays have length

MAX_PIECES=72. One array will hold the x index the other the y index of the location on the board of a checker.  The checkers described in these two lists will be the checkers that can be moved.

Checkers that can be moved include a Soldier or Mule that can move one square diagonally forward and a King that can be move one square diagonally forward or one square diagonally backward.

3.   Declare 2 arrays of xIndicesJump[] andyIndicesJump[]. Each of these arrays have length

MAX_PIECES=72. One array will hold the x index the other the y index of the location on the board of a checker.  The checkers described in these two lists will be the checkers that can jump one of the

opponents checkers.

4. Declare the following global constants

const int MAX_ARRAY_SIZE = 18;

const int MAX_ARRAY_SIZE = 18;

const int MIN_ARRAY_SIZE = 8;

const int MAX_PIECES = 72;

const int NOPLAYER = 0;

const int WHITEWINS = 1;

const int REDWINS = 2;

const int NOONEWINS = 0;

const int WHITESOLDIER = 1;

const int WHITEMULE = 2;

const int WHITEKING = 3;

const int REDSOLDIER = 4;

const int REDMULE = 5;

const int REDKING = 6;

const int WHITEPLAYER = 1;

const int REDPLAYER = 2;

HINT: Depending on the details of your implementation you may of may not need to use WHITEWINS, REDWINS, or MAX_PIECES.

5.   Prompt for and read the size of the board (numRowsInBoard). Use the following prompt

Enter the number of squares along each edge of the board

6.   Check the board size entered by the user.

The correct range for board size is 8 <= numRowsInBoard <= 18, numRowsInBoard must be even. If the board size is not valid one of the following error messages should be printed

ERROR: Board size too large.

ERROR: Board size too small.

ERROR: Board size odd.

ERROR: Board size is not an integer.

7.   If the user enters an invalid value or a value that is out of range, tell the user what legal values are by printing the message

printing the message

8 <= number of squares <= 18

and reprompt for and reread a new value. Read the value a maximum of 3 times, if the value is still invalid or out of range print the message below and terminate the program.

ERROR: Too many errors entering the size of the board.

8.  Initialize the game board using the InitializeBoard function.

a)  Declare the array myCMCheckersBoard to hold the game board in the main program (HINT: Please remember all variables should be declared at the start of the main program)

b) Initialize this array to hold all 0’s when you create it

c) Use the function InitializeBoard to place all the checkers in their initial positionsPrint the initial board to the screen using the DisplayBoard functionFor each turn (White moves first)

9.   Print the initial board to the screen using the DisplayBoard function

10.   For each turn (White moves first)

a) Check if the player has a possible legal move by calling

functions countJump and countMove1Squares. The return value of countJumps tells you how

many of your checkers are able to jump the opponent’s checkers. The return value of  tells you the    sum of how many Mules and Soldiers can be can be moved one space forward and how many kings can be moved.

HINT: The player must press return after entering the character to close the game.

b) If there is no possible move print one of the following groups of messages

White is unable to move.

GAME OVER, Red has won.

Enter any character to close the game.

HINT: The player must press return after entering the character to close the game.

c) If the player can move at least one checker print one of the following single line message to the screen.

White takes a turn.

Red takes a turn.

d) Request the number of the square containing the checker the player wishes to move. The number of the square will be displayed on the gameboard. For example the initial gameboard for an 8x8

board would be like that shown below. The square number of the square is shown for each empty    square. WS is shown for each white soldier checker, WM for each white mule checker, RM for each red mule checker and RS for each red soldier checker.

0 WS 16 24 32 RS 48

RM

WM

9

WS

25

33

41

RS

57

2

WS

18

26

34

RS

50

RM

WM

11

WS

27

35

43

RS

59

4

WS

20

28

36

RS

52

RM

WM

13

WS

29

37

45

RS

61

6

WS

22

30

38

RS

54

RM

WM

15

WS

31

39

47

RS

63

Red is unable to move

GAME OVER, White has won

Enter any character to close the game

e) When requesting square containing the checker to move use the following prompt

Enter the square number of the checker you want to move

i. If the value of the square number could not be read print the error message below and reprompt

ERROR: You did not enter an integer

Try again

ii. If the chosen square is not on the board print the error message below and reprompt.

ERROR: That square is not on the board.

Try again

iii. If the chosen square is occupied by an opponent’s checker, print the error message below and reprompt

ERROR: That square contains an opponents checker.

Try again

iv. If the chosen square contains no checker, print the error message below and reprompt

ERROR: That square is empty.

Try again

Try again

v. If the checker you chose cannot jump an opponents checker but there is another of your

checkers that can jump an opponents checker, than you cannot move your chosen checker so print the error message below and reprompt

ERROR: You can jump with another checker, you may not move your chosen checker.

You can jump using checkers on the following squares: 45 49

Try again

vi. If the checker you chose cannot jump and cannot move at all then print the error message below and reprompt

ERROR: There is no legal move for this checker.

Try again

f) After you have successfully selected a checker to move you must indicate where you wish to move the checker to. For each attempt at choosing the square to move the checker to.

i. Prompt the user to request the square to which the player wishes to move the checker

Enter the square number of the square you want to move your checker to

ii. If the value of the square number could not be read print the error message and reprompt

ERROR: You did not enter an integer.

Try again

iii.     If the chosen square is not on the board print the error message below and reprompt

ERROR: It is not possible to move to a square that is not on the board.

Try again

iv. If the chosen square  is already occupied,  print an error message below and reprompt

ERROR: It is not possible to move to a square that is already occupied.

Try again

v. If the chosen square  is diagonally adjacent to the space where the checker started (if you   have requested to move 1 step diagonally)  but the checker you have selected can also jump, print an error message below

ERROR: You can jump with this checker, you must jump not move 1 space.

Try again

Try again

g) Call MakeMove to move your checker to the desired square.

h) Print the initial board to the screen using the DisplayBoard function

i) If MakeMove returns false then the move you have requested is not a legal move, print the following error message and then go back to the beginning of step e)

ERROR: Moving to that square is not legal, Try again.

j) If MakeMove returns true you have completed the first part of your move

k) If you jumped when you completed the the first part of your move, the value of jumped returned

from MakeMove will be true. If jumped is true you must check to see if you can jump again as part of this move.

l) Call IsJump using the present (after the jump) location of your checker. If IsJump is false your move has been completed.

m) If IsJump is true set the square number of the checker you want to move to be the present location of the checker you just moved.

n) Prompt the user with the message

You can jump again, Please enter the next square you wish to move your checker to

The possible error messages when the  player enters the new next square will be identical to those  in step f).  When you reprompt use the prompt given in this step.  After entering an acceptable value of the new next square continue with the following steps.

o) Call MakeMove to move your checker to the ne