From bab349b6ec357efda03f3c646a8af01ac530f1d2 Mon Sep 17 00:00:00 2001 From: Matt Strapp Date: Tue, 27 Apr 2021 14:14:01 -0500 Subject: Publish functional code --- python/alphaBeta.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/alphaBeta.py b/python/alphaBeta.py index 6ac0400..52ede74 100644 --- a/python/alphaBeta.py +++ b/python/alphaBeta.py @@ -26,7 +26,7 @@ class ABNode(object): # A class for Node related operations self.CurrentScore = self.Current.score[2]-self.Current.score[1] def Make(self, r,c,o): # Function for generating a child node - self.children[(r,c,o)] = ABNode(self.Current) + self.children[(r,c,o)] = ABNode(deepcopy(self.Current)) move=(r,c,o) self.children[(r,c,o)].Current.play_move(move) self.children[(r,c,o)].update_score() @@ -41,7 +41,8 @@ class ABNode(object): # A class for Node related operations class AlphaBeta(object): def miniMax(self, State, Ply_num): # Function for the minimax algorithm - start=ABNode(State) + State = deepcopy(State) + start = ABNode(State) possiblemoves=State.get_moves() for x in possiblemoves: if (x[0],x[1],x[2]) not in start.children: @@ -78,7 +79,7 @@ class AlphaBeta(object): c = 0 o="" for k, z in State.children.items(): - Result = AlphaBeta.Minimum(z, Ply_num - 1, Maximum_Score) + Result = self.Minimum(z, Ply_num - 1, Maximum_Score) if Maximum_Score < Result: Maximum_Score = Result if Result > Alpha: @@ -99,7 +100,7 @@ class AlphaBeta(object): i = 0 j = 0 for k, z in State.children.items(): - Result = AlphaBeta.Maximum(z, Ply_num - 1, Minimum_Score) + Result = self.Maximum(z, Ply_num - 1, Minimum_Score) if Minimum_Score > Result: Minimum_Score = Result if Result < Beta: -- cgit v1.2.3