From a4d22cdc52f56d9cd62d0e9739aafb022e326da1 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Fri, 6 Dec 2024 17:40:10 -0500 Subject: [PATCH] inline some functions --- strategic_player.cxx | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/strategic_player.cxx b/strategic_player.cxx index cf5e053..85f5694 100644 --- a/strategic_player.cxx +++ b/strategic_player.cxx @@ -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)) {