aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorJack Vehmeier <vehme003@umn.edu>2021-04-26 23:09:56 -0500
committerJack Vehmeier <vehme003@umn.edu>2021-04-26 23:09:56 -0500
commit41e88c7558fd5de1169ea6a53dd3010579f2ee74 (patch)
treec88edbd83fd62d870a3d49bdfb5755474c68b199 /python
parentfixed node again (diff)
downloadcsci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.tar
csci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.tar.gz
csci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.tar.bz2
csci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.tar.lz
csci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.tar.xz
csci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.tar.zst
csci4511w-41e88c7558fd5de1169ea6a53dd3010579f2ee74.zip
attempted to redo AB pruning completely
Diffstat (limited to 'python')
-rw-r--r--python/alphaBeta.py49
1 files 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