cmpsc330hw4/random_player.cpp
2024-11-19 18:54:26 -05:00

14 lines
476 B
C++

#include "random_player.h"
#include <cstdlib>
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
}