aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2021-04-26 18:26:09 -0500
committerMatt Strapp <strap012@umn.edu>2021-04-26 18:26:09 -0500
commiteae4bb3d3ce9d3401685eeba61ff47343d1d33cf (patch)
tree18f016c778a86d715e1988e0fa6530780a5df7f1
parentDelete useless AB code (diff)
downloadcsci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.tar
csci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.tar.gz
csci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.tar.bz2
csci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.tar.lz
csci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.tar.xz
csci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.tar.zst
csci4511w-eae4bb3d3ce9d3401685eeba61ff47343d1d33cf.zip
refactor things
Diffstat (limited to '')
-rw-r--r--.vscode/launch.json20
-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
5 files changed, 39 insertions, 13 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 1363c44..ba7b0d6 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -35,16 +35,16 @@
"console": "integratedTerminal"
},
//Basically a constructor
- // {
- // "name": "AB",
- // "type": "python",
- // "request": "launch",
- // "program": "${workspaceFolder}/python/agent_AB.py",
- // "args": [
- // "10003",
- // ],
- // "console": "integratedTerminal"
- // },
+ {
+ "name": "AB",
+ "type": "python",
+ "request": "launch",
+ "program": "${workspaceFolder}/python/agent_AB.py",
+ "args": [
+ "10003",
+ ],
+ "console": "integratedTerminal"
+ },
], "compounds": [
{
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()