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...
|
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...
|
|
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.
◆ preProcessInput()
template<class T >
int chessCAMO::preProcessInput |
( |
T |
input | ) |
|
Converts the input string into its corresponding coordinate (integer) for easier computation in chess::makeMove(int src, int dest, istream& in).
- Parameters
-
[in] | input | The input square of the piece (as a string, E.g. "e2") |
- Template Parameters
-
T | Either 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
-
board | The board representation |
reservoir | The 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_message | The input message that will be appended to the final message |
| chess | The 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_screen | Whether the screen should be cleared |
| chess | The chess object is created |
| in | Input 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] | text | The text message to be created |
[in] | color | One 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] | apply | Whether 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_object | The 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_object | The chess object |