logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(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 _ #

(5/5)
Attachments:

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 Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Um e HaniScience

892 Answers

Hire Me
expert
Muhammad Ali HaiderFinance

857 Answers

Hire Me
expert
Husnain SaeedComputer science

937 Answers

Hire Me
expert
Atharva PatilComputer science

537 Answers

Hire Me
April
January
February
March
April
May
June
July
August
September
October
November
December
2025
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
SunMonTueWedThuFriSat
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
00:00
00:30
01:00
01:30
02:00
02:30
03:00
03:30
04:00
04:30
05:00
05:30
06:00
06:30
07:00
07:30
08:00
08:30
09:00
09:30
10:00
10:30
11:00
11:30
12:00
12:30
13:00
13:30
14:00
14:30
15:00
15:30
16:00
16:30
17:00
17:30
18:00
18:30
19:00
19:30
20:00
20:30
21:00
21:30
22:00
22:30
23:00
23:30