CBG  0.1
Compendium of board games
Reversi Class Reference

#include <Reversi.h>

Inheritance diagram for Reversi:
GameWithXYSelector Game

Public Member Functions

 Reversi ()
 
- Public Member Functions inherited from GameWithXYSelector
 GameWithXYSelector (const int amountOfPlayers, const int columns, const int rows)
 
- Public Member Functions inherited from Game
 Game (const int amountOfPlayers, const int columns, const int rows)
 
virtual ~Game ()
 
virtual void start ()
 

Private Member Functions

bool getMove ()
 Gets a move from the player. More...
 
bool isValidMove (int destinationX) const
 Determins if a destination square is valid. More...
 
bool executeMove (Square &destinationSquare) const
 Call the flanks method to ensure the destination coordinate flanks an opponents piece. More...
 
int isOver ()
 Determines if the game has been won or not. More...
 
bool checkNext (Square &current, int yOffset, int xOffset, bool flip) const
 
bool flanks (Square current, bool flip) const
 
bool isLegal (Coordinate current, int iOffset, int jOffset) const
 Checks if the next square is inside the bounds of the board. More...
 

Additional Inherited Members

- Protected Member Functions inherited from GameWithXYSelector
void drawScreen () const
 Prints out the board and the players pieces. More...
 
int getPoint (string message, int range) const
 Prompts with message to get a point between 0 and range. More...
 
int getOpposition () const
 Returns the opposition. More...
 
- Protected Attributes inherited from Game
int currentPlayer
 Holds the position in the players array of the current player. More...
 
Player ** players
 Holds all of the games players. More...
 
Square ** grid
 Holds all of the squares that makes up the games grid. More...
 
const int amountOfPlayers
 Holds the length of the players array. More...
 
const int columns
 Holds the amount of columns within the grid. More...
 
const int rows
 Holds the amount of rows within the grid. More...
 

Detailed Description

Reversi Game.

Author
Peter Morgan

Constructor & Destructor Documentation

Reversi::Reversi ( )

Member Function Documentation

bool Reversi::checkNext ( Square current,
int  yOffset,
int  xOffset,
bool  flip 
) const
private

Checks a line of pieces to see if it ends with a piece that belong to the current player if it does, it flips the line of pieces to the current players colour

Checks a line of pieces to see if it ends with a piece that belong to the Current player, if it does it removes the line of pieces and exchanges them with pieces owned by the current player.

bool Reversi::executeMove ( Square destSquare) const
private

Call the flanks method to ensure the destination coordinate flanks an opponents piece.

Call the flanks method to ensure the destination coordinate flanks an opponents piece. If it does it adds the piece to the destination square.

bool Reversi::flanks ( Square  current,
bool  flip 
) const
private

Checks if a coordinate flanks an opponents piece. Calls check next to see if the piece is inline with an existing piece owned by the same player.

Checks if the current square flanks an opponents piece Boolean flip is passed in to tel the function if we want to flip the pieces or we're just testing if there is a place where a move could be made.

bool Reversi::getMove ( )
privatevirtual

Gets a move from the player.

Calls getPoint to get the destination square validates the move and passes the destination square onto executeMove().

Implements Game.

bool Reversi::isLegal ( Coordinate  current,
int  iOffset,
int  jOffset 
) const
private

Checks if the next square is inside the bounds of the board.

int Reversi::isOver ( )
privatevirtual

Determines if the game has been won or not.

Implements Game.

bool Reversi::isValidMove ( int  destinationX) const
private

Determins if a destination square is valid.


The documentation for this class was generated from the following files: