Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please answer this question. Its due tomorrow night Develop a program to play the game Reversi The design of the program shall make

Can someone please answer this question. Its due tomorrow night

Develop a program to play the game Reversi The design of the program shall make it possible to implement computer players of different strength. However only one (very simple) player is required for the project.

Implementation The program uses several classes. Each class must have its own source code and header file. Equip the header files with include guards. The following types, classes and functions must be implemented.

Piece Piece is an enumeration type that represents the possible contents of a square on the board. A possible definition is

enum Piece {LIGHT, DARK, EMPTY};

Piece can be defined in the header file of the Board class.

Move The program represents moves by a single integer number. This number is the index of square where the new piece is placed in the board array. Move is therefore a typedef that defines Move as an appropriate integer type.

NullMove NullMove is a named constant of type Move that represents a special value. It is used when a player has no legal move.

Board The Board class represents the current state of the board. It contains a one-dimensional array of the board squares and maintains a list of the moves that are possible in the current position. It provides the following member functions: Board(): Default constructor that initializes the board by calling the member function reset(). void reset(): Erases all pieces from the board. void display() const: Displays the board. void makeMove(Piece,Move): Executes the move indicated by the function parameters and calls genMoves(). bool isLegal(Piece,Move) const: Checks whether it is legal to place the given Piece on the square named by the second parameter. Piece getWinner() const: Returns the color of the winning side. If nobody has won yet the function returns EMPTY. Piece getPlayer() const: Returns the color of the Player whose turn it is. void genMoves(): Generates a list of the moves that are possible in the current position [usually called by makeMove()]. int numMoves() const: Returns the number of valid moves. Move getMove(int) const: Returns the move specified by the integer parameter.

Player Player is an abstract base class for the common functionality of human and computer players. It stores the name of the player and the piece he or she uses on the board. The interface contains the following member functions:

Player(const string&,Piece): The constructor of the Player class receives the name of the player and his/her piece color. Piece::getPiece() const: Returns the piece of this player void makeMove(Board&): This is a pure virtual function that makes the players move on the board. A default virtual destructor.

Player has no default constructor. HumanPlayer This class is derived from the class Player. The member function makeMove() prompts the user for the square where he/she wants to place his/her piece.

ComputerPlayer This class is an abstract base class derived from the class Player. The class implements common functionality for all computer player classes. It does not implement the makeMove() member function. The class ensures that different computer players get different names assigned. The first comptuer player is named Computer A, the second computer player is named Computer B, etc. In order to create the names the class uses a static variable of type int or char that is increased every time that an instance of ComputerPlayer is created. The interface of the class only has one member:

ComputerPlayer::ComputerPlayer(Piece): The initializer generates the player's name and passes it to the base class constructor.

RandomPlayer This class implements a very simple computer player. Its implementation of the makeMove() member function makes random (but legal) moves. Like all computer player classes RandomPlayer inherits from ComputerPlayer.

Game The Game class controls the flow of a game. It contains an instance of Board and two Pointers to Player objects as member variables. The class provides the following member functions:

Game::Game(): The default constructor intializes an empty board and sets the player pointers to NULL. Game::~Game(): The destructor deallocates any dynamically allocated objects. void selectPlayers(): Prompts the user for each of the two players for the type (human/computer) of the player. For a human player the function also asks for the player's name. The function then creates the objects for the players dynamically.

Player* nextPlayer() const: The function returns the pointer to the player whose move it is.

void play(): While isRunning returns true, the function displays the boards and invokes the makeMove() member function of the player whose move it is.

void announceWinner(): Announces the end of the game and the name of the winner (or a tie).

main() The main function of the program creates a Game object and then calls its member functions selectPlayers(), play() and announceWinner(). Place this function in its own file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learn To Program Databases With Visual Basic 6

Authors: John Smiley

1st Edition

1902745035, 978-1902745039

More Books

Students also viewed these Databases questions

Question

Find ( 3 1 4 1 4 , 1 4 1 4 1 ) by applying the Euclid s algorithm.

Answered: 1 week ago

Question

=+ How does this differ from the Solow model?

Answered: 1 week ago