aboutsummaryrefslogtreecommitdiff
path: root/include/negamax.c
diff options
context:
space:
mode:
authortslil clingman <tslil@posteo.de>2021-01-26 00:24:03 -0500
committertslil <tslil@posteo.de>2026-08-28 19:37:41 +0100
commit9131e08817ae2f3bd58a8a0ba9f1e692ceb8604c (patch)
tree67ee90f033ad3f3c5f09e7a911f5379c4d45ca51 /include/negamax.c
parent9c151da7ce0d00ecf04e4be9c395604d4c8882ad (diff)
There is still a bug, it doesn't appear to be checking enough
Diffstat (limited to 'include/negamax.c')
-rw-r--r--include/negamax.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/include/negamax.c b/include/negamax.c
index 912705d..8b7345f 100644
--- a/include/negamax.c
+++ b/include/negamax.c
@@ -123,20 +123,22 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
action_take(node);
// Compute the value of the node
+ float node_value;
if (ply >= 2*board_size - 2 && (w = check_win()) < 0xFF) {
- float winnings = -colour*infty;
+ node_value = -colour*infty;
// Check win if far enough into the game
- if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) winnings = colour*infty;
- else if (w == WIN_DRAW) winnings = 0; // Draw is fixed at neutral
- value = fmax(value, winnings);
+ if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) node_value = colour*infty;
+ else if (w == WIN_DRAW) node_value = 0; // Draw is fixed at neutral
} else if (cur_depth > 1) {
// If nobody won, or too early, recurse if not a leaf
- value = fmax(value, -negamax(cur_depth - 1, -beta, -alpha, -colour));
+ node_value = -negamax(cur_depth - 1, -beta, -alpha, -colour);
} else {
// Recursion would take us to a leaf, evaluate
- value = fmax(value, colour*cnn1986_evaluate_black_win());
+ node_value = colour * cnn1986_evaluate_black_win();
}
+ value = fmax(value, node_value);
+
action_undo(node);
negamax_display_progress(cur_depth, list->length);