cmpsc330hw4/random_player.cxx
2024-11-19 22:36:16 -05:00

24 lines
678 B
C++

#include "random_player.h"
#include <cstdlib>
#include <ctime>
RandomPlayer::RandomPlayer(char name) {
this->name = name;
srand(time(0)); // Seed the random number generator
}
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
}
char RandomPlayer::getName() const {
return this->name;
}