MiniGame-Madness
|
A class that represents the game of Hnefatafl. More...
#include <hnefatafl.h>
Public Member Functions | |
void | populateBoard () |
Initializes the game board. More... | |
int | getPiece (int row, int col) |
Gets the piece at a specific position on the board. More... | |
std::pair< int, int > | move (std::pair< int, int > source, std::pair< int, int > target) |
Moves a piece from the source position to the target position. More... | |
bool | isCaptured (std::pair< int, int > position) |
Checks if a piece at the given position is captured. More... | |
void | handleNeighboursCaptured (int row, int col) |
bool | isKingCaptured () |
Checks if the king is captured. More... | |
bool | isGameOver () |
Checks if the game is over. More... | |
std::pair< int, int > | covertMove (const std::string move) |
Converts a string-based move to board coordinates. More... | |
std::pair< int, int > | bot (int player) |
A basic bot to play against the player. More... | |
void | printBoard () |
Prints the current state of the game board. | |
bool | isValidInput (const std::string &input) |
Check for vaild inputs. More... | |
Hnefatafl () | |
Constructs a new Hnefatafl game object. | |
int | run () |
Run the game. More... | |
A class that represents the game of Hnefatafl.
This class provides methods to initialize the game board, handle player moves,
check game conditions, and implement a basic bot for playing against the player.
std::pair< int, int > Hnefatafl::bot | ( | int | player | ) |
A basic bot to play against the player.
player | The player (WHITE or BLACK) for whom the bot will play. |
std::pair< int, int > Hnefatafl::covertMove | ( | const std::string | move | ) |
Converts a string-based move to board coordinates.
move | The move as a string. |
int Hnefatafl::getPiece | ( | int | row, |
int | col | ||
) |
Gets the piece at a specific position on the board.
row | The row index of the position. |
col | The column index of the position. |
void Hnefatafl::handleNeighboursCaptured | ( | int | row, |
int | col | ||
) |
Checks if neighbouring pieces of target piece are captured.
row | The row index of the target piece. |
col | The column index of the target piece. |
bool Hnefatafl::isCaptured | ( | std::pair< int, int > | position | ) |
Checks if a piece at the given position is captured.
position | The position of the piece as a pair of (row, col). |
bool Hnefatafl::isGameOver | ( | ) |
Checks if the game is over.
bool Hnefatafl::isKingCaptured | ( | ) |
Checks if the king is captured.
bool Hnefatafl::isValidInput | ( | const std::string & | input | ) |
Check for vaild inputs.
input | The input from the user |
std::pair< int, int > Hnefatafl::move | ( | std::pair< int, int > | source, |
std::pair< int, int > | target | ||
) |
Moves a piece from the source position to the target position.
source | The source position as a pair of (row, col). |
target | The target position as a pair of (row, col). |
void Hnefatafl::populateBoard | ( | ) |
Initializes the game board.
The board is represented as a 2D array of integers:
0: Empty square
1: White piece
2: Black piece
3: King piece
4: King's square
The board is 11x11 with the center square initially occupied by the king.
The white pieces are placed in a star pattern around the king, with the black pieces in the middle of each side.
The king's squares are in the corners of the board and are the win condition for the king.
int Hnefatafl::run | ( | ) |
Run the game.