diff options
| author | tslil clingman <tslil@posteo.de> | 2021-01-25 00:25:37 -0500 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-08-28 19:37:41 +0100 |
| commit | a32bc9866512886eb56dcdd1197026e8512a4565 (patch) | |
| tree | 814f885ec7147df76277c131c7edc1e956688aa5 /include/negamax.c | |
| parent | 3db577276b055ff7c8a8ed22302e9333ca679c26 (diff) | |
There are still some bugs in the undo almost surely...
Diffstat (limited to 'include/negamax.c')
| -rw-r--r-- | include/negamax.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/include/negamax.c b/include/negamax.c index 757a648..16eba9a 100644 --- a/include/negamax.c +++ b/include/negamax.c @@ -108,39 +108,54 @@ negamax_generate(void) { return result; } +static enum WIN_TYPE w; static float negamax(const uint8_t cur_depth, float alpha, float beta, const float colour) { float value = -infty; - action_list_t *action_list = action_list_generate(); - action_list_t *action = action_list; + action_list_t *list = action_list_generate(); - while (action != NULL) { + for (action_list_t *node=list; node!=NULL; node=node->next) { negamax_display_progress(cur_depth); - action_take(action); - if (cur_depth > 1) { + action_take(node); + + // Somebody won? + if (ply >= 2*board_size - 3 && (w = check_win()) < 0xFF) { + if (w == WIN_ROAD_BLACK || w == WIN_FLAT_BLACK) { + value = colour*infty; + if (value > 0) { + // Always take the win for ourselves + action_undo(node); + if (cur_depth == negamax_search_depth) + action_to_ptn(node, negamax_ptn); + goto prune; + } + } else if (w == WIN_DRAW) value = 0; // Draw is fixed at neutral + else value = -colour*infty; + } else if (cur_depth > 1) { + // Recurse away from the leaves value = fmax(value, -negamax(cur_depth - 1, -beta, -alpha, -colour)); } else { - value = fmax(value, colour*cnn1986_evaluate_black_win()); + // Evaluate a leaf + value = fmax(value, colour * cnn1986_evaluate_black_win()); } - action_undo(action); - // alpha = fmax(alpha, value); + action_undo(node); + if (value > alpha) { alpha = value; if (cur_depth == negamax_search_depth) - action_to_ptn(action, negamax_ptn); + action_to_ptn(node, negamax_ptn); } if (alpha >= beta) break; - - action = action->next; } - action_list_free(action_list); + action_list_free(list); + prune: return value; } |
