diff options
author | Matt Strapp <strap012@umn.edu> | 2021-04-27 14:14:01 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2021-04-27 14:14:01 -0500 |
commit | bab349b6ec357efda03f3c646a8af01ac530f1d2 (patch) | |
tree | 1a552a939b58c4d75e2419d0fe27ecec1225de25 | |
parent | Refactor min to be like max (diff) | |
download | csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.tar csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.tar.gz csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.tar.bz2 csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.tar.lz csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.tar.xz csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.tar.zst csci4511w-bab349b6ec357efda03f3c646a8af01ac530f1d2.zip |
Publish functional code
-rw-r--r-- | python/alphaBeta.py | 9 |
1 files changed, 5 insertions, 4 deletions
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: |