Earn Higher Grades With Instant Assignment Help.Ask Question!

C++ Programming
(5/5)

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

 

  1. Output the board and output the score of each player

  2. 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

  3. 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

  1. 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

  2. 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

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

  4. 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 _ #

Attachments:
(5/5)

Related Questions

Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

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. The LineItem class will represent an individual

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

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
543 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
610 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
636 Answers Hire Me