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

Class representing the Noughts and Crosses (Tic-Tac-Toe) game. More...

#include <NaughtsxCrossess.h>

Public Member Functions

 NaughtsxCrossess ()
 Constructor to initialize the game board.
 
 NaughtsxCrossess (const NaughtsxCrossess &other)
 Copy Constructor.
 
NaughtsxCrossessoperator= (const NaughtsxCrossess &other)
 Copy Assignment Operator.
 
 NaughtsxCrossess (ScreenBuffer *buffer)
 Constructor that accepts an external ScreenBuffer.
 
 ~NaughtsxCrossess ()
 Destructor to clean up internal ScreenBuffer if we own it.
 
void setScreenBuffer (ScreenBuffer *buffer)
 Sets the ScreenBuffer to be used by the game.
 
void printBoard () const
 Prints the current state of the board.
 
void run (std::function< std::string()> inputProvider=nullptr)
 Runs and manages the game.
 
void printBoardWithNumbers () const
 Prints the board with numbers 1-9 to indicate cell positions.
 
bool isMovesLeft () const
 Checks if there are any moves left on the board. More...
 
int evaluate () const
 Evaluates the current board and returns a score. More...
 
int minimax (int depth, bool isMax, int difficulty)
 Minimax algorithm to calculate the best move for the AI. More...
 
std::pair< int, int > findBestMove (int difficulty)
 Finds the best move for the AI based on the current board state. More...
 
bool playerMove (char player, std::function< std::string()> inputProvider=nullptr)
 Handles player input for a move with optional input simulation for testing. More...
 
void aiMove (int difficulty)
 Handles the AI's move based on the selected difficulty level. More...
 
void clearScreen () const
 Clears the console screen.
 
void resetBoard ()
 Resets the game board, clearing all pieces and setting it to the initial state. More...
 
char & getBoardValue (int row, int col)
 Get a reference to the value of the board at a specific position. More...
 

Detailed Description

Class representing the Noughts and Crosses (Tic-Tac-Toe) game.

Member Function Documentation

◆ aiMove()

void NaughtsxCrossess::aiMove ( int  difficulty)

Handles the AI's move based on the selected difficulty level.

Parameters
difficultyThe difficulty level of the AI.

◆ evaluate()

int NaughtsxCrossess::evaluate ( ) const

Evaluates the current board and returns a score.

Returns
+10 if 'X' wins, -10 if 'O' wins, 0 otherwise.

◆ findBestMove()

std::pair< int, int > NaughtsxCrossess::findBestMove ( int  difficulty)

Finds the best move for the AI based on the current board state.

Parameters
difficultyThe difficulty level of the AI.
Returns
The best move as a pair of integers representing row and column.

◆ getBoardValue()

char & NaughtsxCrossess::getBoardValue ( int  row,
int  col 
)

Get a reference to the value of the board at a specific position.

Parameters
rowThe row index of the board.
colThe column index of the board.
Returns
A reference to the value at the specified position.

◆ isMovesLeft()

bool NaughtsxCrossess::isMovesLeft ( ) const

Checks if there are any moves left on the board.

Returns
True if there are moves left, false otherwise.

◆ minimax()

int NaughtsxCrossess::minimax ( int  depth,
bool  isMax,
int  difficulty 
)

Minimax algorithm to calculate the best move for the AI.

Parameters
depthThe current depth of the recursion.
isMaxTrue if the AI is maximizing, false if minimizing.
difficultyThe depth limit for Medium difficulty.
Returns
The evaluated score.

◆ playerMove()

bool NaughtsxCrossess::playerMove ( char  player,
std::function< std::string()>  inputProvider = nullptr 
)

Handles player input for a move with optional input simulation for testing.

Parameters
playerThe character representing the player ('x' or 'o').
inputProviderA function or lambda that provides input for testing.
Returns
False if the player typed "stop", true otherwise.

◆ resetBoard()

void NaughtsxCrossess::resetBoard ( )

Resets the game board, clearing all pieces and setting it to the initial state.

This is called at the start of each new game.


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