inline some functions

This commit is contained in:
Sandipsinh Rathod 2024-12-06 17:40:10 -05:00
parent 9e4af98d6c
commit a4d22cdc52
No known key found for this signature in database

@ -6,6 +6,25 @@ extern "C" IPlayer* PlayerFactory()
return new StrategicPlayer();
}
// Helper functions
inline int normalize(int x) {
return (x + 1) >> 1;
}
inline char getPoint(Board &board, const int row, const int col) {
return board(row, col);
}
inline bool isLineValid(Board &board, const int row, const int col) {
return (row > -1 && row < board.GetRows() && col > -1 && col < board.GetCols()) &&
((row & 1) != (col & 1)) && (getPoint(board, row, col) == ' ');
}
void set(Board &board, int r, int c, char ch) {
board(r, c) = ch;
}
//
string StrategicPlayer::PlayerInfo() {
return "Sandipsinh Rathod (sdr5549@psu.edu), Sapan Shah (scs6041@psu.edu)";
@ -26,24 +45,6 @@ void StrategicPlayer::Close() {
board.FreeBoard();
}
int normalize(int x) {
return (x + 1) >> 1;
}
char getPoint(Board &board, const int row, const int col) {
return board(row, col);
}
bool isLineValid(Board &board, const int row, const int col) {
return (row > -1 && row < board.GetRows() && col > -1 && col < board.GetCols()) &&
((row & 1) != (col & 1)) && (getPoint(board, row, col) == ' ');
}
void set(Board &board, int r, int c, char ch) {
board(r, c) = ch;
}
/// TODO: check if we needs checks :)
void StrategicPlayer::EventAddLine(char bar, const Loc &loc) {
set(board, loc.row, loc.col, bar);
@ -101,7 +102,7 @@ void selectLine(Board &board, int &row, int &col, int rows, int cols, char name)
}
// Step 2: Avoid moves that leave a box with one line remaining
#pragma omp parallel for
#pragma omp parallel for collapse(2)
for (int r = 0; r < 2 * rows - 1; ++r) {
// Iterate over all valid rows
for (int c = 0; c < 2 * cols - 1; ++c) {
@ -144,6 +145,7 @@ void selectLine(Board &board, int &row, int &col, int rows, int cols, char name)
}
// Step 3: Fallback to the first valid move
#pragma omp parallel for collapse(2)
for (int r = 0; r < 2 * rows - 1; ++r) {
for (int c = 0; c < 2 * cols - 1; ++c) {
if (isLineValid(board, r, c)) {