diff options
author | Matt Strapp <strap012@umn.edu> | 2021-04-26 18:26:09 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2021-04-26 18:26:09 -0500 |
commit | eae4bb3d3ce9d3401685eeba61ff47343d1d33cf (patch) | |
tree | 18f016c778a86d715e1988e0fa6530780a5df7f1 /python/alphaBeta.py | |
parent | Delete useless AB code (diff) | |
download | csci4511w-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-- | python/alphaBeta.py | 26 |
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 |