From 41e88c7558fd5de1169ea6a53dd3010579f2ee74 Mon Sep 17 00:00:00 2001 From: Jack Vehmeier Date: Mon, 26 Apr 2021 23:09:56 -0500 Subject: attempted to redo AB pruning completely --- python/alphaBeta.py | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/python/alphaBeta.py b/python/alphaBeta.py index be44c85..66040d5 100644 --- a/python/alphaBeta.py +++ b/python/alphaBeta.py @@ -25,7 +25,7 @@ class ABNode(object): # A class for Node related operations elif self.Current.player == 1: self.CurrentScore = self.Current.score[2]-self.Current.score[1] - def Make(self, r,c,o, player): # Function for generating a child node + def Make(self, r,c,o): # Function for generating a child node self.children[(r,c,o)] = ABNode(self.Current) move=(r,c,o) self.children[(r,c,o)].play_move(move) @@ -41,40 +41,41 @@ class ABNode(object): # A class for Node related operations class AlphaBeta(object): def miniMax(State, Ply_num): # Function for the minimax algorithm - - for i in range(State.Current.dimY): - for j in range(State.Current.dimX): - if State.Current.Mat[i][j] == ' ' and (j, i) not in State.children: - State.Make(j, i, True) - if Ply_num < 2: - return (i, j) + possiblemoves=State.get_moves() + for x in possiblemoves: + if (x[0],x[1],x[2]) not in State.children: + State.Make(x[0],x[1],x[2]) + if Ply_num < 2: + return (i, j) Minimum_Score = 1000 - i = 0 - - j = 0 + r = 0 + c = 0 + o = "" for k, z in State.children.items(): Result = Algo.Maximum(z, Ply_num - 1, Minimum_Score) if Minimum_Score > Result: Minimum_Score = Result - i = k[0] - j = k[1] + r = k[0] + c = k[1] + o = k[2] - return (i, j) + return (r,c,o) # Alpha-beta pruning function for taking care of Alpha values def Maximum(State, Ply_num, Alpha): if Ply_num == 0: return State.CurrentScore - for i in range(State.Current.dimY): - for j in range(State.Current.dimX): - if State.Current.Mat[i][j] == ' ' and (j, i) not in State.children: - State.Make(j, i, False) + possiblemoves=State.get_moves() + for x in possiblemoves: + if (x[0],x[1],x[2]) not in State.children: + State.Make(x[0],x[1],x[2]) Maximum_Score = -1000 - i = 0 - j = 0 + r = 0 + c = 0 + o="" for k, z in State.children.items(): Result = Algo.Minimum(z, Ply_num - 1, Maximum_Score) if Maximum_Score < Result: @@ -88,10 +89,10 @@ class AlphaBeta(object): if Ply_num == 0: return State.CurrentScore - for i in range(State.Current.dimY): - for j in range(State.Current.dimX): - if State.Current.Mat[i][j] == ' ' and (j, i) not in State.children: - State.Make(j, i, True) + possiblemoves=State.get_moves() + for x in possiblemoves: + if (x[0],x[1],x[2]) not in State.children: + State.Make(x[0],x[1],x[2]) Minimum_Score = 1000 i = 0 -- cgit v1.2.3