aboutsummaryrefslogtreecommitdiff
path: root/include/negamax.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/negamax.c')
-rw-r--r--include/negamax.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/include/negamax.c b/include/negamax.c
index f6a7525..7f05040 100644
--- a/include/negamax.c
+++ b/include/negamax.c
@@ -131,6 +131,7 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
uint64_t hash = zobrist_compute();
tt_entry_t *entry = tt_seek(hash);
+ // CAUTION: >= breaks search stability
if (entry != NULL && entry->depth == cur_depth) {
if (entry->flag == TT_EXACT) {
return entry->value;
@@ -146,15 +147,16 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
if ((list = action_list_generate()) == NULL)
return alpha; // should never happen!
+ if (entry != NULL) {
+ action_move_to_front(entry->action, list);
+ }
- /*
- * action_node_t *best = NULL;
- */
-
+ action_t best_action;
float value = -infty;
+
for (action_node_t *node=list->head; node!=NULL; node=node->next) {
- action_take(node);
+ action_take(node->action);
// Compute the value of the node
float node_value;
if (ply >= 2*board_size - 2 && (w = check_win()) < 0xFF) {
@@ -168,14 +170,15 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
} else {
node_value = colour * cnn1986_evaluate_black_win();
}
- action_undo(node);
+ action_undo(node->action);
negamax_display_progress(cur_depth, list->length);
if (node_value > value) {
value = node_value;
+ best_action = node->action;
if (cur_depth == negamax_search_depth)
- action_to_ptn(node, negamax_ptn);
+ action_to_ptn(node->action, negamax_ptn);
}
alpha = fmax(value, alpha);
@@ -189,12 +192,12 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
else if (value <= alpha) flag = TT_UPPERBOUND;
if (entry == NULL) {
- tt_insert(hash, flag, cur_depth, value);
+ tt_insert(hash, flag, cur_depth, value, best_action);
} else {
entry->flag = flag;
entry->value = value;
entry->depth = cur_depth;
- // entry->action = best;
+ entry->action = best_action;
}
return value;