Trabalho Prático - PDS2
Carregando...
Procurando...
Nenhuma entrada encontrado
Referência da Classe Reversi
Diagrama de hierarquia da classe Reversi:
Diagrama de colaboração para Reversi:

Membros Públicos

 Reversi ()
 Constructs a Reversi game with an 8x8 board and initializes the starting positions.
 
void makeMove () override
 Executes a move in the Reversi game.
 
char isGameFinished () override
 Checks if the game of Reversi is finished.
 
- Membros Públicos herdados de Game
 Game (int rows, int cols)
 Constructs a new Game object with the specified number of rows and columns.
 
void changePlayer ()
 
virtual void printBoard ()
 Prints the current state of the game board to the standard output.
 

Membros privados

void readMove () override
 Reads a move from the user and validates it.
 
void validateMove (const int row, const int col)
 Validates a move in the Reversi game.
 
void checkPosition (const int row, const int col)
 Checks if the specified position on the board is occupied.
 
void checkBoundaries (const int row, const int col)
 Checks if the given row and column are within the boundaries of the board.
 
void checkDirections (const int row, const int col)
 Checks all possible directions from a given position on the board.
 
bool checkDirection (const int row, const int col, char other, const Direction &dir)
 Checks a specific direction from a given position on the board to find and mark opponent's pieces to be captured.
 

Atributos Privados Estáticos

static const Direction _dirs []
 Array of possible directions for the Reversi game.
 

Outros membros herdados

- Atributos Protegidos herdados de Game
Board board
 
std::pair< int, int > move
 
char current_player
 

Documentação das funções

◆ checkBoundaries()

void checkBoundaries ( const int row,
const int col )
private

Checks if the given row and column are within the boundaries of the board.

Parâmetros
rowThe row index to check.
colThe column index to check.
Exceções
InvalidInputExceptionif the row or column is out of the board's boundaries.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ checkDirection()

bool checkDirection ( const int row,
const int col,
char other,
const Direction & dir )
private

Checks a specific direction from a given position on the board to find and mark opponent's pieces to be captured.

This function checks in the specified direction (given by dir) from the position (row, col) on the board. It looks for a sequence of opponent's pieces (other) that are bounded by the current player's piece. If such a sequence is found, the positions of the opponent's pieces are added to the list of pieces to be captured (toEat).

Parâmetros
rowThe starting row position on the board.
colThe starting column position on the board.
otherThe character representing the opponent's pieces.
dirThe direction to check, represented by a Direction object containing dx and dy.
Retorna
true if the direction is valid and contains opponent's pieces to be captured, false otherwise.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ checkDirections()

void checkDirections ( const int row,
const int col )
private

Checks all possible directions from a given position on the board.

This function iterates through all 8 possible directions (up, down, left, right, and the four diagonals) from the specified row and column on the board.

Parâmetros
rowThe row index of the starting position on the board.
colThe column index of the starting position on the board.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ checkPosition()

void checkPosition ( const int row,
const int col )
private

Checks if the specified position on the board is occupied.

Parâmetros
rowThe row index of the position to check.
colThe column index of the position to check.
Exceções
InvalidInputExceptionif the position is occupied.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ isGameFinished()

char isGameFinished ( )
overridevirtual

Checks if the game of Reversi is finished.

This function determines if the game has ended by checking for valid moves for the current player. If no valid moves are found, it switches to the other player and checks again. If neither player has valid moves, the game is considered finished. The function then counts the pieces for each player on the board and returns the result.

Retorna
'E' if the game is not finished and there are valid moves. 'X' if player 'X' has more pieces and wins. 'O' if player 'O' has more pieces and wins. 'D' if the game is a draw (both players have the same number of pieces).

Implementa Game.

Este é o diagrama das funções utilizadas por essa função:

◆ makeMove()

void makeMove ( )
overridevirtual

Executes a move in the Reversi game.

This function performs the following steps:

  1. Determines the opponent's piece based on the current player.
  2. Reads the move from the player.
  3. Sets the player's piece on the board at the specified move position.
  4. Checks all 8 possible directions from the move position to find and flip the opponent's pieces.
  5. Flips the opponent's pieces to the current player's pieces if they are bounded by the current player's pieces.
  6. Changes the current player to the opponent.

Implementa Game.

Este é o diagrama das funções utilizadas por essa função:

◆ readMove()

void readMove ( )
overrideprivatevirtual

Reads a move from the user and validates it.

Exceções
InvalidInputExceptionif the move is invalid.

Implementa Game.

Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

◆ validateMove()

void validateMove ( const int row,
const int col )
private

Validates a move in the Reversi game.

This function checks if a move is valid by verifying the position, boundaries, and possible directions for flipping opponent's pieces.

Parâmetros
rowThe row index of the move.
colThe column index of the move.
Este é o diagrama das funções utilizadas por essa função:
Esse é o diagrama das funções que utilizam essa função:

Campos

◆ _dirs

const Direction _dirs
staticprivate
Valor inicial:
= {
Direction(-1, 1),
Direction(0, 1),
Direction(1, 1),
Direction(1, 0),
Direction(1, -1),
Direction(0, -1),
Direction(-1, -1),
Direction(-1, 0)
}
Definição reversi.hpp:10

Array of possible directions for the Reversi game.

This array contains all the possible directions in which a move can be made in the Reversi game. Each direction is represented by a Reversi::Direction object, which takes two parameters indicating the change in row and column respectively.

Directions included:

  • (-1, 1): Down-Left
  • (0, 1): Down
  • (1, 1): Down-Right
  • (1, 0): Right
  • (1, -1): Up-Right
  • (0, -1): Up
  • (-1, -1): Up-Left
  • (-1, 0): Left

A documentação para essa classe foi gerada a partir dos seguintes arquivos: