[Solved] COMP 2160 Programming Practices Assignment 2

$25

File Name: COMP_2160_Programming_Practices_Assignment_2.zip
File Size: 414.48 KB

SKU: [Solved] COMP 2160 Programming Practices Assignment 2 Category: Tag:
5/5 - (1 vote)

NOTES

  • Please read and follow instructions carefully; not doing so will result in a loss of marks.
  • You must complete Honesty Declaration form digitally in UMLearn.
  • Your code must follow the programming standards (available in UMLearn).
  • You can write your code on any machines; remember to verify your code on one of the lab machines.
  • You must include a README file which describes how to compile and run your solution. You can also explain your concerns or personal opinions regarding this assignment.
  • Use submission tool (handin) in CS Unix system as described in Assignment Submission Guidelines (available in UMLearn).

REVERSI (OTHELLO) [20]

Download reversi_skeleton.c and rename it to reversi.c. Then, implement the incomplete functions: checkstate(), canPlayAt(), and numReverseDirection(). Your implementation must follow the design by contract principle. In addition, make your solution fail gracefully in production (i.e., when assertion is disabled).

The code is to read a Reversi game board from standard input, compute the best move for a player, and print the result to standard output. In our case, the best move refers to a move which allows the player to capture the most opponents pieces. If you want to learn more about the game, you can read the Wikipedia entry (https://en.wikipedia.org/wiki/Reversi); I have listed the game rules that you need for this assignment.

  • there are two players, black and white
  • each player can only play at the place where they capture the opponents piece(s)
  • when a piece placed, we check if there are opponents pieces wrapped by the players o we check 8-direction (4 straights, up, down, left, right; and 4 diagonals, left-up, left-down, right-up, right-down) by moving along on this direction

o if we found the players piece along the way, the opponents pieces in between are captured and becomes the players

  • we get the number of captures for a specific position by adding every directions captures

Implementation Requirements

All following conditions must be met by your solution void checkstate( const GameBoard * board )

This function should check if the given board is valid. Our valid state means

  • nColumns is (0, MAX_BOARD_COLUMNS), i.e., 0 < nColumns < MAX
  • nRows is (0, MAX_BOARD_ROWS), i.e., 0 < nRows < MAX
  • player is either BLACK or WHITE boolean canPlayAt( const GameBoard * board, int row, int col )

This function should check if the opponents piece is around given position (i.e., check 8-direction). For example, if current player is BLACK, you need to find out if WHITEs piece appears as a neighbour.

int numReverseDirection( const GameBoard * board, int row, int col, int dirRow, int dirCol )

This function should count and return the number of opponents pieces which are wrapped in between players. At the given column and row, the players piece is played. You must move toward the given direction [-1, 1] to count the opponent pieces. If you could not find the players piece along the given direction, the count should be zero.

BONUS [1]

If you completed this bonus question, write a note for a marker in the readme file. For this bonus, update the readGameBoard() routine to handle any error in input. The correct input format is

  • first line is the boards title
  • second line contains three space separated items o first item is the number of columns o second item is the number of rows
    • third item is either B or W which indicates whos the player is
  • from third line, the board presents o each line represents each row of the board
    • each character on a line represents each column of the board o each cell is B, W, or space character
  • at the end, there is an empty line

Your updated function must be able to detect incorrect input format and return false. Use assertions to follow the design by contract principle and help you to debug. In addition, use safeguard to gracefully fail the process in production. You can write any helper functions.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP 2160 Programming Practices Assignment 2
$25