From c4430810836a97619eda0730a90f34d47a8abdb8 Mon Sep 17 00:00:00 2001 From: Nemo Date: Mon, 28 May 2018 19:55:49 +0530 Subject: [PATCH] Game traversal happening (no limits = crash) --- gothok/game.py | 16 ++++++++++++++-- gothok/mcts.py | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gothok/game.py b/gothok/game.py index 4e8fe63..8f02250 100644 --- a/gothok/game.py +++ b/gothok/game.py @@ -55,15 +55,26 @@ class State(): if (card.house == picked_card.house): # Pick it up picked_cards.append(card) - self.board[row][col] = game.House.empty + empty_card = game.Card.new_message() + empty_card.house = game.House.empty + self.board[row][col] = empty_card - print(picked_cards) + return self def findVarys(self): for card in self.state.cardlist: if card.house == 'varys': return card.location + """ + Returns true if the game has + reached the final state ie + there are no legal possible moves + """ + + def gameOver(self): + return (len(self.getPossibleMoves()) == 0) + def getPossibleMoves(self): moves = [] @@ -105,6 +116,7 @@ class State(): seen = {} for (xx, yy) in l: + print(self.board[xx][yy]) house = self.board[xx][yy].house if str(house) in seen: return False diff --git a/gothok/mcts.py b/gothok/mcts.py index edde17b..e418470 100644 --- a/gothok/mcts.py +++ b/gothok/mcts.py @@ -34,14 +34,15 @@ class GameNode(object): return (w / n) + (c * math.sqrt(log(t) / n)) def runSimulation(self): + print(self.state) self.backPropagate(self.simulate()) def simulate(self): state = self.state - while not state.gameOver: + while not state.gameOver(): moves = state.getPossibleMoves() - randomMove = random.choice(possibleMoves) + randomMove = random.choice(moves) state = state.playMove(randomMove) return self.state.result(state)