aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-26 18:14:22 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commitef65e760347ff695654627934ac347fce4b63511 (patch)
tree21e6bdcb22dff9c03d6037ec067fb5fe959f64be /include
parentde4f20f28afe23ecfc546ad242e5bb44710996cc (diff)
Small changes to build ct1986
Diffstat (limited to 'include')
-rw-r--r--include/negamax.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/include/negamax.c b/include/negamax.c
index 7f05040..061b629 100644
--- a/include/negamax.c
+++ b/include/negamax.c
@@ -93,20 +93,6 @@ negamax_free(void) {
zobrist_free();
}
-static enum WIN_TYPE w;
-
-static inline float
-negamax_evaluate_terminal(const float colour) {
- if (ply >= 2*board_size - 2 && (w = check_win()) < 0xFF) {
- // Check win if far enough into the game
- if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) return colour*infty;
- else if (w == WIN_DRAW) return 0; // Draw is fixed at neutral
- else return -colour*infty;
- } else {
- return colour * cnn1986_evaluate_black_win();
- }
-}
-
float
negamax_generate(void) {
// We need to start with something outside of [-∞,∞] because those
@@ -123,6 +109,7 @@ negamax_generate(void) {
}
static enum TT_FLAG flag;
+static enum WIN_TYPE w;
static float
negamax(const uint8_t cur_depth, float alpha, float beta,
@@ -151,8 +138,9 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
action_move_to_front(entry->action, list);
}
- action_t best_action;
- float value = -infty;
+ // TODO: what to do if this is never written to?
+ action_t best_action = list->head->action;
+ float best_value = -infty;
for (action_node_t *node=list->head; node!=NULL; node=node->next) {
@@ -162,8 +150,11 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
if (ply >= 2*board_size - 2 && (w = check_win()) < 0xFF) {
node_value = -colour*infty;
// Check win if far enough into the game
- if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) node_value = colour*infty;
- else if (w == WIN_DRAW) node_value = 0; // Draw is neutral
+ if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) {
+ node_value = colour*infty;
+ } else if (w == WIN_DRAW) {
+ node_value = 0;
+ }
} else if (cur_depth > 1) {
// If nobody won, or too early and not leaf, recurse
node_value = -negamax(cur_depth - 1, -beta, -alpha, -colour);
@@ -174,31 +165,31 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
negamax_display_progress(cur_depth, list->length);
- if (node_value > value) {
- value = node_value;
+ if (node_value > best_value) {
+ best_value = node_value;
best_action = node->action;
if (cur_depth == negamax_search_depth)
action_to_ptn(node->action, negamax_ptn);
}
- alpha = fmax(value, alpha);
+ alpha = fmax(best_value, alpha);
if (alpha >= beta) break;
}
action_list_free(list);
flag = TT_EXACT;
- if (value >= beta) flag = TT_LOWERBOUND;
- else if (value <= alpha) flag = TT_UPPERBOUND;
+ if (best_value >= beta) flag = TT_LOWERBOUND;
+ else if (best_value <= alpha) flag = TT_UPPERBOUND;
if (entry == NULL) {
- tt_insert(hash, flag, cur_depth, value, best_action);
+ tt_insert(hash, flag, cur_depth, best_value, best_action);
} else {
entry->flag = flag;
- entry->value = value;
+ entry->value = best_value;
entry->depth = cur_depth;
entry->action = best_action;
}
- return value;
+ return best_value;
}