inline some functions
This commit is contained in:
parent
a4d22cdc52
commit
565c69594c
@ -20,7 +20,7 @@ inline bool isLineValid(Board &board, const int row, const int col) {
|
||||
((row & 1) != (col & 1)) && (getPoint(board, row, col) == ' ');
|
||||
}
|
||||
|
||||
void set(Board &board, int r, int c, char ch) {
|
||||
inline void set(Board &board, int r, int c, char ch) {
|
||||
board(r, c) = ch;
|
||||
}
|
||||
//
|
||||
@ -55,11 +55,14 @@ void StrategicPlayer::EventAddBox(char box, const Loc &loc) {
|
||||
}
|
||||
|
||||
void selectLine(Board &board, int &row, int &col, int rows, int cols, char name) {
|
||||
int max_row = 2 * rows - 2;
|
||||
int max_col = 2 * cols - 2;
|
||||
|
||||
// Step 1: Try to complete a box
|
||||
#pragma omp parallel for collapse(2)
|
||||
for (int r = 1; r < 2 * rows - 2; r += 2) {
|
||||
for (int r = 1; r < max_row; r += 2) {
|
||||
// Iterate over box centers (odd rows)
|
||||
for (int c = 1; c < 2 * cols - 2; c += 2) {
|
||||
for (int c = 1; c < max_col; c += 2) {
|
||||
// Iterate over box centers (odd cols)
|
||||
// Check adjacent lines for an opportunity to complete a box
|
||||
if (isLineValid(board, r - 1, c) && // Top line
|
||||
@ -113,15 +116,15 @@ void selectLine(Board &board, int &row, int &col, int rows, int cols, char name)
|
||||
|
||||
// Check if this move leaves a box with only one line remaining
|
||||
bool createsOpportunity = false;
|
||||
for (int nr = 1; nr < 2 * rows - 2; nr += 2) {
|
||||
for (int nr = 1; nr < max_row; nr += 2) {
|
||||
// Iterate over box centers
|
||||
for (int nc = 1; nc < 2 * cols - 2; nc += 2) {
|
||||
for (int nc = 1; nc < max_col; nc += 2) {
|
||||
if (getPoint(board, nr, nc) == ' ') {
|
||||
int adjacentLines = 0;
|
||||
if (nr > 0 && getPoint(board, nr - 1, nc) != ' ') adjacentLines++; // Top line
|
||||
if (nr < 2 * rows - 2 && getPoint(board, nr + 1, nc) != ' ') adjacentLines++; // Bottom line
|
||||
if (nr < max_row && getPoint(board, nr + 1, nc) != ' ') adjacentLines++; // Bottom line
|
||||
if (nc > 0 && getPoint(board, nr, nc - 1) != ' ') adjacentLines++; // Left line
|
||||
if (nc < 2 * cols - 2 && getPoint(board, nr, nc + 1) != ' ') adjacentLines++; // Right line
|
||||
if (nc < max_col && getPoint(board, nr, nc + 1) != ' ') adjacentLines++; // Right line
|
||||
|
||||
if (adjacentLines == 3) {
|
||||
// Opponent can complete this box
|
||||
|
Loading…
Reference in New Issue
Block a user