chessCAMO
Functions
chessCAMO Namespace Reference

This namespace contains the global functions related to chessCAMO which are mainly used as helper functions to print information to the console to improve user experience while playing the game. More...

Functions

template<class T >
int preProcessInput (T input)
 Converts the input string into its corresponding coordinate (integer) for easier computation in chess::makeMove(int src, int dest, istream& in). More...
 
void printBoard (const vector< Piece * > &board, const vector< pair< int, char >> &reservoir)
 Iterates through the pieces on a current board representation to produce the board on the console screen. More...
 
void printFooterMessage (string input_message, const Chess &chess)
 Prints the footer message before each move indicating whose move it is for the current board representation. More...
 
void drawOrResign (bool clear_screen, Chess &chess, istream &in)
 At any moment, the players can either continue, draw, or resign. More...
 
void printMessage (string text, int color)
 Prints the given message ('text') with a given 'color' to console. More...
 
void clearScreen (bool apply)
 Clears the screen of the console window using a special string instead of a platform specific command. More...
 
void saveObject (const Chess &chess_object)
 Saves an object by serializing its member fields to a text file, allowing it to later be reset. More...
 
void restoreObject (Chess &chess_object)
 De-serializes an object from a file based on the number of moves made, essentially restoring the object's saved properties (in the file). More...
 

Detailed Description

This namespace contains the global functions related to chessCAMO which are mainly used as helper functions to print information to the console to improve user experience while playing the game.

Function Documentation

◆ preProcessInput()

template<class T >
int chessCAMO::preProcessInput ( input)

Converts the input string into its corresponding coordinate (integer) for easier computation in chess::makeMove(int src, int dest, istream& in).

Parameters
[in]inputThe input square of the piece (as a string, E.g. "e2")
Template Parameters
TEither string or integer type
Returns
The source or destination squares in integer form
Note
Can use integers as well due to template functionality

◆ printBoard()

void chessCAMO::printBoard ( const vector< Piece * > &  board,
const vector< pair< int, char >> &  reservoir 
)

Iterates through the pieces on a current board representation to produce the board on the console screen.

Parameters
boardThe board representation
reservoirThe reservoir of pieces
Postcondition
Each piece of the current board representation is printed to the screen using a corresponding letter inside a formatted board. Additionally, the piece reservoir information is displayed beneath the board representation.

◆ printFooterMessage()

void chessCAMO::printFooterMessage ( string  input_message,
const Chess chess 
)

Prints the footer message before each move indicating whose move it is for the current board representation.

Parameters
[in]input_messageThe input message that will be appended to the final message
chessThe chess object

◆ drawOrResign()

void chessCAMO::drawOrResign ( bool  clear_screen,
Chess chess,
istream &  in 
)

At any moment, the players can either continue, draw, or resign.

Parameters
[in]clear_screenWhether the screen should be cleared
chessThe chess object is created
inInput stream is selected (stdin or file)
Precondition
None
Postcondition
Depending on the users choice, the program either continues ('y' || 'd' + 'n' || 'u') or terminates ('d' + 'y' || 'r')

◆ printMessage()

void chessCAMO::printMessage ( string  text,
int  color 
)

Prints the given message ('text') with a given 'color' to console.

Parameters
[in]textThe text message to be created
[in]colorOne of the defined values at the top of the file
Precondition
None
Postcondition
The message is printed to the screen with color chosen and then the color is changed back to default prior to return

◆ clearScreen()

void chessCAMO::clearScreen ( bool  apply)

Clears the screen of the console window using a special string instead of a platform specific command.

Parameters
[in]applyWhether to in fact clear or not

◆ saveObject()

void chessCAMO::saveObject ( const Chess chess_object)

Saves an object by serializing its member fields to a text file, allowing it to later be reset.

Parameters
[in]chess_objectThe chess object

◆ restoreObject()

void chessCAMO::restoreObject ( Chess chess_object)

De-serializes an object from a file based on the number of moves made, essentially restoring the object's saved properties (in the file).

Parameters
chess_objectThe chess object