aboutsummaryrefslogtreecommitdiffstats
path: root/python/alphaBeta.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/alphaBeta.py')
-rw-r--r--python/alphaBeta.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/python/alphaBeta.py b/python/alphaBeta.py
index fb30391..214ed23 100644
--- a/python/alphaBeta.py
+++ b/python/alphaBeta.py
@@ -1,11 +1,35 @@
+import math
+from copy import deepcopy
+from time import perf_counter
+from random import choice
+
from GameState import GameState
class GameController(object):
def get_next_move(self, state):
# when you get a new move, it is assumed that the game is not ended yet
assert state.get_moves()
+class ABNode(object): # A class for Node related operations
+ def __init__(self, state):
+ self.Current = state
+ self.CurrentScore = 0
+ self.children = {}
+
+ def Make(self, i, j, player): # Function for generating a child node
+ self.children[(i, j)] = ABNode(self.Current.Get_currentState())
+ mul = 1
+ if player:
+ mul *= -1
+ self.children[(i, j)].CurrentScore = (self.children[(i, j)].Current.action(i, j) * mul) + self.CurrentScore
+
+ def Populate(self, i, j, Child): # Function for adding a node
+ self.children[(i,j)] = Child
+
+ def Draw(self): # function for drawing the board
+ self.Current.Draw_mat()
+
# A class for defining algorithms used (minimax and alpha-beta pruning)
-class AlphaBeta:
+class AlphaBeta(object):
def miniMax(State, Ply_num): # Function for the minimax algorithm