logo Use SA10RAM to get 10%* Discount.
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Jason ParkerrEngineering
(5/5)

545 Answers

Hire Me
expert
Priyanka TanwarCriminology
(5/5)

938 Answers

Hire Me
expert
Thomas BornholdttEnglish
(5/5)

638 Answers

Hire Me
expert
Hardik DixitSociology
(5/5)

893 Answers

Hire Me
C++ Programming

you will implement the game called reversi, to get an idea of how the game works, you may try it out using the following link Reversi Game.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

For this assignment, you will implement the game called reversi, to get an idea of how the game works, you may try it out using the following link Reversi Game. The rules are explained in the following link Reversi Rules. You will implement the game class and inherit that to the reversi class, the class declarations can be seen below

 

class game

 

{

 

public :

 

const static int DIMENSION = 4; game ();

 

bool update Board ( int , int , char );

 

char get Character On Board ( int , int ) const ; private :

 

char board [ DIMENSION ][ DIMENSION ];

 

};

 

 

 

class reversi : game

 

{

 

public : reversi ();

 

bool move Can Be Made ( bool ) const ; bool make Move ( int , int , bool ); int is Over () const ;

 

string get Board () const ; int get Score ( bool ) const ;

 

private :

 

int p 1 Score ; int p 2 Score ;

 

};

 

Each member of the game class contains/performs the following

 

 

 

const static int DIMENSION - denotes the size of the game board, if the value is 4, then the game board will be a 4 by 4 board

 

char board[DIMENSION][DIMENSION] - contains the characters on the game board

 

 

 

game::game() - default constructor that sets each element of board to an underscore character, i.e. the ’_’ character

 

bool game::updateBoard(int r, int c, char item) - sets the board at index [r][c] with item, if it can be updated then update that character at that position and return true, if the indices passed into the function are out of bounds, do not update the board, just simply return false

 

char game::getCharacterOnBoard(int r, int c) const - returns the character at position [r][c]

 

of the board, if the indices are out of bounds, then return the null character, i.e. return ’\0’

 

 

 

Each member of the reversi class contains/performs the following

 

 

 

int p1Score - keeps track of player 1’s score

 

int p2score - keeps track of player 2’s score

 

reversi::reversi() - sets all the characters on the board array (which is a private member of the base class) and sets the board to contain ’#’ and ’$’ onto the middle of the board (see initial board output in the sample output), do not hard code this, make sure it sets these characters to the middle regardless of the value in DIMENSION, you will also set player1Score and player2Score to be 2

 

bool reversi::moveCanBeMade(bool turn) const - function determines if a legal move can be done by either player 1 or player 2, if the value true is passed into the function, then we are checking if player 1 can make a legal move, and if false passed into the function then we are checking if player 2 can make a legal move; returns true if a legal move can be done and returns false otherwise

 

bool reversi::makeMove(int x, int y, bool turn) - places the character ’#’ into position [x][y] of the board array (must be a vacant spot) if turn contains true (which implies player 1 is making a move); or this places the ’$’ into position [x][y] of the board array (must be a vacant spot); then you will traverse all the directions and try to flip each character; then update player 1’s and players 2’s score; and return true; however for some reason the coordinates passed in results in an illegal move (either x and y are out of bounds or by placing a character to position [x][y] can’t flip any of the characters around it), in this case do not modify the board and return false

 

int reversi::isOver() const - returns 2 if the game is not over, returns 1 if neither player 1 or player 2 can make a move and player 1 has a larger score, returns -1 if neither player 1 or player 2 can make a move and player 2 has a larger score, returns 0 if neither player can make a move and the game ends in a tie

 

string reversi::getBoard() const - returns the board in a form of a string to be used in an output statement in main

 

int reversi::getScore(bool turn) const - returns player 1’s score if the value in turn contains

 

true; returns player 2’s score if the value in turn contains false

 

Contents of main

 

In main, once you declare the object of type reversi, you do the following

 

 

 

Output the board and output the score of each player

 

Check if player 1 can make a move, if player 1 can go to the next step otherwise output player 1 passes and go to step 4

 

Prompt the user for coordinates

 

If either value is a not a valid number, prompt the user again

 

If valid numbers are read in, but the function makeMove returns false then re-prompt

 

If valid input and makeMove returns true, output the board and go onto the next step

 

Check if player 2 can make a move, if player 1 can go to the next step otherwise output player 1 passes and go to step

 

Prompt the user for coordinates

 

If either value is a not a valid number, prompt the user again

 

If valid numbers are read in, but the function makeMove returns false then re-prompt

 

If valid input and makeMove returns true, output the board and go onto the next step

 

If isOver() returns 2, then go to step 1, otherwise go to the next step

 

Based on what isOver() returns, output the winner or a tie

 

Specifications

 

Document your code and your functions

 

Use variables with meaningful names

 

Make sure your code is error proof

 

Do not modify the class (do not change the prototypes of the functions, or add or remove any functions)

 

All of the user input and output is done in main, main calls the class members functions to modify/re- trieve data

 

No global variables

 

Example Output

 

 $ make

 

g++ - c main . cpp g++ - c reversi . cpp g++ - c game . cpp

 

g++ main . o reversi . o game . o

 

$ ./ a. out

 

 

 

0 1 2 3

 

0 _ _ _ _

 

1 _ # $ _

 

2 _ $ # _

 

3 _ _ _ _

 

 

 

Player 1 Score = 2 Player 2 Score = 2

 

 

 

Player 1: -9 8

 

Player 1: 0 2

 

 

 

0 1 2 3

 

0 _ _ # _

 

1 _ # # _

 

2 _ $ # _

 

3 _ _ _ _

 

 

 

Player 1 Score = 4 Player 2 Score = 1

 

Player 2: 0 0 Player 2: hi bye Player 2: 0 1

 

0 1 2 3

 

0 _ $ # _

 

1 _ $ # _

 

2 _ $ # _

 

3 _ _ _ _

 

 

 

Player 1 Score = 3 Player 2 Score = 3

 

Player 1: 0 0

 

0 1 2 3

 

0 # # # _

 

1 _ # # _

 

2 _ $ # _

 

3 _ _ _ _

 

Player 1 Score = 6 Player 2 Score = 1

 

Player 2: 0 3

 

 

 

0 1 2 3

 

0 # # # $

 

1 _ # $ _

 

2 _ $ # _

 

3 _ _ _ _

 

 

 

Player 1 Score = 5 Player 2 Score = 3

 

Player 1: 1 0

 

Player 1: 1 3

 

0 1 2 3

 

0 # # # $

 

1 _ # # #

 

2 _ $ # _

 

3 _ _ _ _

 

Player 1 Score = 7 Player 2 Score = 2

 

Player 2: 2 3

 

0 1 2 3

 

0 # # # $

 

1 _ # # $

 

2 _ $ $ $

 

3 _ _ _ _

 

 

 

 

 

Player 1 Score = 5 Player 2 Score = 5

 

 

 

Player 1: 3 1

 

 

 

0 1 2 3

 

0 # # # $

 

1 _ # # $

 

2 _ # $ $

 

3 _ # _ _

 

 

 

 

 

Player 1 Score = 7 Player 2 Score = 4

 

 

 

Player 2: 1 0

 

 

 

0 1 2 3

 

0 # # # $

 

1 $ $ $ $

 

2 _ # $ $

 

3 _ #

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

402 Experts Online