alpha_beta.c
changeset 96 810acedf60d8
parent 87 b2f1756c17ca
child 97 f883331a1bf2
--- a/alpha_beta.c
+++ b/alpha_beta.c
@@ -74,7 +74,6 @@
     board[stack_end->data->target] = EMPTY;
 
     actual = stack_end->prev;
-    free (stack_end->data);
     free (stack_end);
 
     stack_end = actual;
@@ -227,14 +226,21 @@
         undo ();
         t++;
 
-        if (moveValue >= beta)
+        if (moveValue >= beta) {
+            free (move);
             return beta;
+        }
 
         if (moveValue > alpha) {
             alpha = moveValue;
-            if (depth == desired_depth)
+            if (depth == desired_depth) {
+                if (bestMove != NULL)
+                    free (bestMove);
                 bestMove = move;
+                continue;
+            }
         }
+        free (move);
     }
 
     return alpha;
@@ -264,6 +270,7 @@
             moveValue = max_alpha_beta (depth - 1, alpha, beta);
 
         undo ();
+        free (move);
         t++;
 
         if (moveValue <= alpha)
@@ -338,6 +345,7 @@
         }
 
         board[bestMove->target] = 'O';
+        free (bestMove);
         print ();
 
         if ((estimateFunction () * estimateFunction ()) == 2500) {