Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following design of game of chess. Chessobject chessboard[][] chess

ID: 666874 • Letter: C

Question

Consider the following design of game of chess.

Chessobject chessboard[][]

chessboard is a two dimensional array of size 8 X 8. It represents a chessboard in the game of chess. It holds chess objects.

chessboard[2][3] = whitepawn1 means currently on my chessboard, I have whitepawn1 on cell 2,3.

chessboard[6][3] = blackpawn4 means blackpawn4 on cell 6,3.

chessboard[5][1] = null means cell 5,1 is empty.

By defining all 64 cells on the chessboard, we have a state of game of chess.

As we will play the game of chess, we will remove objects from the game of chess.

Chessobject discardpile[] is a one dimensional array of 32 size that holds removed chess object from the game of chess.

Combinely chessboard[][] and discardpile[] defines a valid state of game of chess. Though the definition is not complete, but let’s assume that it is a valid state of game of chess for rest of our discussion.

I define RookMove method as follows. Remember, rook moves in horizontal and vertical direction and cannot jump over a piece.

bool RookMove(ChessObject[][] chessboard, ChessObject[] discardpile, ChessObject rookObject, int a, int b, int x, int y)

first two parameters are current state of game. Assume that as third parameter, I will always pass correct rook object. whiterook1, whiterook2, blackrook1 or blackrook2.

a,b is the source position of the rook that was passed to the method. Assume that passed rook is indeed at position a,b.

x,y is the destination position of the rook. The cell where the rook is supposed to move.

If the move is legal, necessary changes will be made to chessboard and discardpile and method will return true.

If the move is illegal, no changes will be made to chessboard and discardpile and method will return false.

It is important to note that the changes in chessboard and discardpile will help us to determine if RookMove is doing its job correctly or not.

Consider one particular move.

RookMove(chessboard, discardpile, whiterook1, 2,7,2,3)

I am trying to move rook-whiterook1 from 2,7 position to 2,3 position.

I want you to test this particular call. So, don't spend time doing a generic testing of RookMove. Just tell me how you will test this particular call.

RookMove(chessboard, discardpile, whiterook1, 2,7,2,3)

As you can see, I am trying to move rook in horizontal direction.

Provide 3 test cases (unit test - pseudo code) for testing the particular call. Describe your test using verbal scenario first and then write pseudo code. Pseudo code should look like “code”. Assert appropriately.

Explanation / Answer

TEST CASE 1:

RookMove(chessboard, discardpile, whiterook1, 2,7,2,3)

Input:   

Output:

               chessboard[2][7] = whitepawn1 moved to chessboard[2][3]

Status: Moved horizontal direction

pseudo code :

TEST CASE 2:

RookMove(chessboard, discardpile, blackpawn4, 3,1,4,1)

Input:   

Output:

               chessboard[3][1] = blackpawn4 moved to chessboard[4][1]

Status: Moved Vertical direction

TEST CASE 2:

RookMove(chessboard, discardpile, blackpawn4, 0,0,0,0)

Input:   

Output:

               chessboard[0][0] = blackpawn4 moved to chessboard[0][0]

Status: Object not moved