My Project
UML Lab
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes | List of all members
Board Class Reference

Represents the game board and its functionality. More...

#include <board.h>

Public Member Functions

 Board (Player &red, Player &black)
 Constructor for the Board class.
 
PlayergetRedPlayer ()
 Getter for the red player.
 
PlayergetBlackPlayer ()
 Getter for the black player.
 
void InitializeGame (Player &redPlayer, Player &blackPlayer)
 Initializes the game board with pieces.
 
bool validarity (const Piece &piece, int x, int y)
 Checks the validity of a move for a given piece.
 
void inputdata (sf::RenderWindow &window)
 Handles player input for moving pieces.
 
bool isPieceAt (int x, int y) const
 Checks if there is a piece at the given coordinates.
 
void highlight (int pieceIndex, sf::RenderWindow &window, Board &board)
 Highlights the possible moves for a selected piece.
 
int numberofmoves (Player *player)
 Counts the number of possible moves for a player.
 
bool endgame ()
 Checks if the game has ended.
 
void draw (sf::RenderWindow &window)
 Draws the game board and pieces on the SFML window.
 
int evaluateBoard (Board &board)
 Evaluates the current state of the board.
 
MoveNode MinMaxTree (Board &board, int depth, bool computerPlayer)
 Implements the Minimax algorithm to search for the best move.
 
Move BestMove (int depth, bool computerPlayer)
 Finds the best move using the Minimax algorithm.
 
bool opponentPiece (int x, int y, const sf::Color &colorToCheck)
 Checks if a piece at a certain position belongs to the opponent.
 
std::vector< MovegenerateMoves (Board &board)
 Generates all possible moves for the current board state.
 
int minimax (Board &board, int depth, bool computerPlayer)
 Minimax algorithm to evaluate the board and choose the best move.
 
void ComputerMove ()
 Executes the computer's move.
 
int MousePosition (int mouseX, int mouseY)
 Generates the index of the piece that was clicked by the mouse.
 
void makeMove (Board &board, const Move &move)
 Makes a move on the board.
 

Public Attributes

PlayerredPlayer
 Reference to the red player.
 
PlayerblackPlayer
 
Piece pieces [24]
 

Static Public Attributes

static constexpr int size = 8
 

Private Attributes

int selectedPieceIndex = -1
 Index of the currently selected piece.
 
const int depth = 5
 Depth for the minimax algorithm.
 

Detailed Description

Represents the game board and its functionality.

Constructor & Destructor Documentation

◆ Board()

Board::Board ( Player & red,
Player & black )

Constructor for the Board class.

Parameters
redThe red player.
blackThe black player.

Member Function Documentation

◆ BestMove()

Move Board::BestMove ( int depth,
bool computerPlayer )

Finds the best move using the Minimax algorithm.

Determines the best move for the computer player.

Parameters
depthThe depth of the search tree.
computerPlayerBoolean indicating if it's the computer's turn.
Returns
The best move found.
Parameters
depthThe depth of the Minimax algorithm.
computerPlayerTrue if the computer is playing, false otherwise.
Returns
The best move.

◆ ComputerMove()

void Board::ComputerMove ( )

Executes the computer's move.

◆ draw()

void Board::draw ( sf::RenderWindow & window)

Draws the game board and pieces on the SFML window.

Draws the board and pieces on the SFML window.

Parameters
windowThe SFML window.

◆ endgame()

bool Board::endgame ( )

Checks if the game has ended.

Returns
True if the game has ended, false otherwise.

◆ evaluateBoard()

int Board::evaluateBoard ( Board & board)

Evaluates the current state of the board.

Evaluates the board for the Minimax algorithm.

Parameters
boardThe current board.
Returns
The evaluation score of the board.
Parameters
boardThe game board.
Returns
The evaluated score.

◆ generateMoves()

std::vector< Move > Board::generateMoves ( Board & board)

Generates all possible moves for the current board state.

Generates possible moves for all pieces on the board.

Parameters
boardThe current board.
Returns
A vector containing all possible moves.
Parameters
boardThe game board.
Returns
A vector of possible moves.

◆ getBlackPlayer()

Player & Board::getBlackPlayer ( )

Getter for the black player.

Returns
Reference to the black player.

◆ getRedPlayer()

Player & Board::getRedPlayer ( )

Getter for the red player.

Returns
Reference to the red player.

◆ highlight()

void Board::highlight ( int pieceIndex,
sf::RenderWindow & window,
Board & board )

Highlights the possible moves for a selected piece.

Parameters
pieceIndexThe index of the selected piece.
windowThe SFML window.
boardThe game board.

◆ InitializeGame()

void Board::InitializeGame ( Player & redPlayer,
Player & blackPlayer )

Initializes the game board with pieces.

Parameters
redPlayerThe red player.
blackPlayerThe black player.

◆ inputdata()

void Board::inputdata ( sf::RenderWindow & window)

Handles player input for moving pieces.

Parameters
windowThe SFML window.

◆ isPieceAt()

bool Board::isPieceAt ( int x,
int y ) const

Checks if there is a piece at the given coordinates.

Parameters
xThe x-coordinate.
yThe y-coordinate.
Returns
True if there is a piece, false otherwise.
Parameters
xThe x-coordinate.
yThe y-coordinate.
Returns
True if a piece is found at the coordinates, false otherwise.

◆ makeMove()

void Board::makeMove ( Board & board,
const Move & move )

Makes a move on the board.

Parameters
boardThe current board state.
moveThe move to make.
boardThe game board.
moveThe move to make.

◆ minimax()

int Board::minimax ( Board & board,
int depth,
bool computerPlayer )

Minimax algorithm to evaluate the board and choose the best move.

Implements the Minimax algorithm for move selection.

Parameters
boardThe current board state.
depthThe depth of the search tree.
computerPlayerBoolean indicating if it's the computer's turn.
Returns
The evaluation score of the board.
Parameters
boardThe game board.
depthThe depth of the Minimax algorithm.
computerPlayerTrue if the computer is playing, false otherwise.
Returns
The score of the board state.

◆ MinMaxTree()

MoveNode Board::MinMaxTree ( Board & board,
int depth,
bool computerPlayer )

Implements the Minimax algorithm to search for the best move.

Generates the Minimax tree and returns the best move.

Parameters
boardThe current board state.
depthThe depth of the search tree.
computerPlayerBoolean indicating if it's the computer's turn.
Returns
The MoveNode representing the best move found.
Parameters
boardThe game board.
depthThe depth of the tree.
computerPlayerTrue if the computer is playing, false otherwise.
Returns
The best move.

◆ MousePosition()

int Board::MousePosition ( int mouseX,
int mouseY )

Generates the index of the piece that was clicked by the mouse.

Gets the index of the piece at the given mouse coordinates.

Parameters
mouseXThe x-coordinate of the mouse.
mouseYThe y-coordinate of the mouse.
Returns
The index of the clicked piece.
Parameters
mouseXThe x-coordinate of the mouse.
mouseYThe y-coordinate of the mouse.
Returns
The index of the piece.

◆ numberofmoves()

int Board::numberofmoves ( Player * player)

Counts the number of possible moves for a player.

Parameters
playerThe player.
Returns
The number of possible moves.

◆ opponentPiece()

bool Board::opponentPiece ( int x,
int y,
const sf::Color & colorToCheck )

Checks if a piece at a certain position belongs to the opponent.

Checks if there is an opponent piece at the given coordinates.

Parameters
xThe x-coordinate of the piece.
yThe y-coordinate of the piece.
colorToCheckThe color of the opponent.
Returns
True if the piece belongs to the opponent, false otherwise.
Parameters
xThe x-coordinate.
yThe y-coordinate.
colorToCheckThe color to check against.
Returns
True if there is an opponent piece, false otherwise.

◆ validarity()

bool Board::validarity ( const Piece & piece,
int x,
int y )

Checks the validity of a move for a given piece.

Parameters
pieceThe piece to check the move for.
xThe x-coordinate of the destination.
yThe y-coordinate of the destination.
Returns
True if the move is valid, false otherwise.

Member Data Documentation

◆ blackPlayer

Player& Board::blackPlayer

◆ depth

const int Board::depth = 5
private

Depth for the minimax algorithm.

◆ pieces

Piece Board::pieces[24]

◆ redPlayer

Player& Board::redPlayer

Reference to the red player.

◆ selectedPieceIndex

int Board::selectedPieceIndex = -1
private

Index of the currently selected piece.

< The size of the board. Array of pieces on the board. Reference to the black player.

◆ size

constexpr int Board::size = 8
staticconstexpr

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