2024-11-19 23:54:26 +00:00
|
|
|
#include "random_player.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2024-11-20 00:11:06 +00:00
|
|
|
|
|
|
|
RandomPlayer::RandomPlayer(char name) {
|
|
|
|
this->name = name;
|
|
|
|
srand(time(0)); // Seed the random number generator
|
|
|
|
}
|
|
|
|
|
2024-11-19 23:54:26 +00:00
|
|
|
void RandomPlayer::selectLineLocation(Board& board, int& row, int& col) {
|
|
|
|
int rows = board.getRows();
|
|
|
|
int cols = board.getCols();
|
|
|
|
|
|
|
|
// Loop until a valid move is found
|
|
|
|
do {
|
|
|
|
row = rand() % (2 * rows - 1); // Random row within the board dimensions
|
|
|
|
col = rand() % (2 * cols - 1); // Random column within the board dimensions
|
|
|
|
} while (!board.isLineValid(row, col)); // Check if the move is valid
|
|
|
|
}
|
2024-11-20 00:11:06 +00:00
|
|
|
|
|
|
|
char RandomPlayer::getName() const {
|
|
|
|
return this->name;
|
|
|
|
}
|