#include "openmp_search.h" int value1(int side[]) { int v = side[houses]; if (v > 24) /* win */ return 100; if (v == 24) /* draw or better */ return 50; return v; } int value(int thisside[], int otherside[]) { return value1(thisside) - value1(otherside); } int alpha_beta_bestmove(int depth, int thisside[], int otherside[], int *vp) { int current_value[houses]; #pragma omp parallel for for (int move = 0; move < houses; move++) { current_value[move] = MIN_INFINITY; int ts1[BOARD_SIZE], os1[BOARD_SIZE]; memcpy(ts1, thisside, BOARD_ARRAY_SIZE); memcpy(os1, otherside, BOARD_ARRAY_SIZE); if (plyfull(move, ts1, os1)) { current_value[move] = value(ts1, os1); if (depth > 0 && current_value[move] <= 50 && current_value[move] >= -50) { current_value[move] = -helper_alpha_beta_search(depth - 1, MIN_INFINITY, MAX_INFINITY, os1, ts1); } } } int best_move = -1; int alpha = MIN_INFINITY; for (int move = 0; move < houses; move++) { if (current_value[move] > alpha) { best_move = move; alpha = current_value[move]; } } *vp = alpha; return best_move; } int helper_alpha_beta_search(int depth, int alpha, int beta, int thisside[], int otherside[]) { int ts1[BOARD_SIZE], os1[BOARD_SIZE]; for (int move = 0; move < houses; move++) { memcpy(ts1, thisside, BOARD_ARRAY_SIZE); memcpy(os1, otherside, BOARD_ARRAY_SIZE); if (plyfull(move, ts1, os1)) { int current_value = value(ts1, os1); if (depth > 0 && current_value <= 50 && current_value >= -50) { current_value = -helper_alpha_beta_search(depth - 1, -beta, -alpha, os1, ts1); } if (current_value > alpha) { if (current_value >= beta) { return current_value; } alpha = current_value; } } } return alpha; }