aboutsummaryrefslogtreecommitdiff
path: root/include/negamax.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/negamax.c')
-rw-r--r--include/negamax.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/include/negamax.c b/include/negamax.c
index 812f8f7..757a648 100644
--- a/include/negamax.c
+++ b/include/negamax.c
@@ -83,8 +83,8 @@ zobrist_free(void) {
void
negamax_init(const uint8_t new_board_size) {
board_size = new_board_size;
+ action_list_init();
zobrist_init();
- action_list_init(board_size);
}
void
@@ -115,26 +115,28 @@ negamax(const uint8_t cur_depth, float alpha, float beta,
float value = -infty;
action_list_t *action_list = action_list_generate();
+ action_list_t *action = action_list;
- for (action_list_t *action = action_list;
- action != NULL;
- action = action->next) {
-
+ while (action != NULL) {
negamax_display_progress(cur_depth);
+ action_take(action);
if (cur_depth > 1) {
- value = colour*cnn1986_evaluate_black_win();
- } else {
- action_take(action);
value = fmax(value, -negamax(cur_depth - 1, -beta, -alpha, -colour));
- action_undo(action);
+ } else {
+ value = fmax(value, colour*cnn1986_evaluate_black_win());
}
+ action_undo(action);
+
// alpha = fmax(alpha, value);
if (value > alpha) {
alpha = value;
- action_to_ptn(action, negamax_ptn);
+ if (cur_depth == negamax_search_depth)
+ action_to_ptn(action, negamax_ptn);
}
if (alpha >= beta) break;
+
+ action = action->next;
}
action_list_free(action_list);