👨👩👦👦
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PoolRaveMctsAgent(RaveMctsAgent): | |
def __init__(self, state: GameState = GameState(8)): | |
super().__init__(state) | |
self.black_rave = {} | |
self.white_rave = {} | |
def set_gamestate(self, state: GameState) -> None: | |
""" | |
Set the root_state of the tree to the passed gamestate, this clears all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LGRMctsAgent(RaveMctsAgent): | |
def __init__(self, state: GameState = GameState(8)): | |
super().__init__(state) | |
self.black_reply = {} | |
self.white_reply = {} | |
def set_gamestate(self, state: GameState) -> None: | |
""" | |
Set the root_state of the tree to the passed gamestate, this clears all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecisiveMoveMctsAgent(RaveMctsAgent): | |
def roll_out(self, state: GameState) -> tuple: | |
""" | |
Simulate a random game except that we play all known critical cells | |
first, return the winning player and record critical cells at the end. | |
""" | |
moves = state.moves() | |
good_moves = moves.copy() | |
good_opponent_moves = moves.copy() | |
to_play = state.turn() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def would_lose(self, cell: tuple, color: int) -> bool: | |
""" | |
Return True is the move indicated by cell and color would lose the game, | |
False otherwise. | |
""" | |
connect1 = False | |
connect2 = False | |
if color == GameMeta.PLAYERS['black']: | |
if cell[1] == 0: | |
connect1 = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import (Frame, Canvas, ttk, HORIZONTAL, VERTICAL, IntVar, Scale, Button, Label, PhotoImage, BOTH, LEFT, Y, | |
X, TOP, messagebox) | |
from numpy import int_ | |
from gamestate import GameState | |
from meta import GameMeta | |
from rave_mctsagent import (RaveMctsAgent, LGRMctsAgent, PoolRaveMctsAgent, DecisiveMoveMctsAgent) | |
from ucb1_tuned_mctsagent import UCB1TunedMctsAgent | |
from uct_mcstsagent import UctMctsAgent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RaveMctsAgent(UctMctsAgent): | |
def __init__(self, state: GameState = GameState(8)): | |
self.root_state = deepcopy(state) | |
self.root = RaveNode() # Replace Node with RaveNode | |
self.run_time = 0 | |
self.node_count = 0 | |
self.num_rollouts = 0 | |
def set_gamestate(self, state: GameState) -> None: | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt, log | |
from copy import deepcopy | |
from random import choice, random | |
from time import clock | |
from gamestate import GameState | |
from uct_mcstsagent import Node, UctMctsAgent | |
from meta import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import Tk | |
from gui import Gui | |
def main(): | |
root = Tk() | |
interface = Gui(root) | |
root.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MCTSMeta: | |
EXPLORATION = 0.5 | |
RAVE_CONST = 300 | |
RANDOMNESS = 0.5 | |
POOLRAVE_CAPACITY = 10 | |
K_CONST = 10 | |
A_CONST = 0.25 | |
WARMUP_ROLLOUTS = 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import (Frame, Canvas, ttk, HORIZONTAL, VERTICAL, IntVar, Scale, Button, Label, PhotoImage, BOTH, LEFT, Y, | |
X, TOP, messagebox) | |
from numpy import int_ | |
from gamestate import GameState | |
from meta import GameMeta | |
from uct_mcstsagent import UctMctsAgent |
NewerOlder