MiniGame-Madness
Public Member Functions | List of all members
Hnefatafl Class Reference

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...
 

Detailed Description

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.

Member Function Documentation

◆ bot()

std::pair< int, int > Hnefatafl::bot ( int  player)

A basic bot to play against the player.

Parameters
playerThe player (WHITE or BLACK) for whom the bot will play.
Returns
A pair representing the bot's chosen move as (row, col).

◆ covertMove()

std::pair< int, int > Hnefatafl::covertMove ( const std::string  move)

Converts a string-based move to board coordinates.

Parameters
moveThe move as a string.
Returns
A pair representing the move as (row, col).

◆ getPiece()

int Hnefatafl::getPiece ( int  row,
int  col 
)

Gets the piece at a specific position on the board.

Parameters
rowThe row index of the position.
colThe column index of the position.
Returns
The piece at the specified position.

◆ handleNeighboursCaptured()

void Hnefatafl::handleNeighboursCaptured ( int  row,
int  col 
)

Checks if neighbouring pieces of target piece are captured.

Parameters
rowThe row index of the target piece.
colThe column index of the target piece.

◆ isCaptured()

bool Hnefatafl::isCaptured ( std::pair< int, int >  position)

Checks if a piece at the given position is captured.

Parameters
positionThe position of the piece as a pair of (row, col).
Returns
true if the piece is captured, false otherwise.

◆ isGameOver()

bool Hnefatafl::isGameOver ( )

Checks if the game is over.

Returns
true if the game is over (either by king capture or escape), false otherwise.

◆ isKingCaptured()

bool Hnefatafl::isKingCaptured ( )

Checks if the king is captured.

Returns
true if the king is captured, false otherwise.

◆ isValidInput()

bool Hnefatafl::isValidInput ( const std::string &  input)

Check for vaild inputs.

Parameters
inputThe input from the user
Returns
true if the input is valid, false otherwise.

◆ move()

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.

Parameters
sourceThe source position as a pair of (row, col).
targetThe target position as a pair of (row, col).
Returns
A pair representing the result of the move.

◆ populateBoard()

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.

◆ run()

int Hnefatafl::run ( )

Run the game.

Returns
Whether should return to the main menu (0) or exit the program (1)

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