aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--python/MCTS.py1
-rw-r--r--python/agent_AB.py2
-rw-r--r--python/alphaBeta.py26
-rw-r--r--python/dotsandboxes/dotsandboxesserver.py3
4 files changed, 29 insertions, 3 deletions
diff --git a/python/MCTS.py b/python/MCTS.py
index 6c71ba9..cf67f48 100644
--- a/python/MCTS.py
+++ b/python/MCTS.py
@@ -21,6 +21,7 @@ class MCTSNode(object):
"""
def __init__(self, state, parent=None, move=None):
+
self.parent = parent
self.move = move
self.state = state
diff --git a/python/agent_AB.py b/python/agent_AB.py
index 5564f11..4a44a83 100644
--- a/python/agent_AB.py
+++ b/python/agent_AB.py
@@ -4,7 +4,7 @@ import dotsandboxes.dotsandboxesagent as dba
import sys
import argparse
import logging
-from GameState import GameState, DotsAndBoxesState
+from GameState import DotsAndBoxesState
import alphaBeta
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
diff --git a/python/dotsandboxes/dotsandboxesserver.py b/python/dotsandboxes/dotsandboxesserver.py
index 1b66372..0a1ed87 100644
--- a/python/dotsandboxes/dotsandboxesserver.py
+++ b/python/dotsandboxes/dotsandboxesserver.py
@@ -23,7 +23,8 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == "/":
self.send_response(302)
- self.send_header("Location", "static/dotsandboxes.html")
+ self.send_header(
+ "Location", "python/dotsandboxes/static/dotsandboxes.html")
self.end_headers()
return super().do_GET()