From 5449cc2a257299203af4e7bfa2d9e8616e6a7e0e Mon Sep 17 00:00:00 2001 From: Nemo Date: Sat, 21 Apr 2018 22:09:09 +0530 Subject: [PATCH] updates --- gothok/README.md | 2 +- gothok/game.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gothok/README.md b/gothok/README.md index fe31d9c..89d53f3 100644 --- a/gothok/README.md +++ b/gothok/README.md @@ -22,4 +22,4 @@ Card lists can be found at the following 2 images: If there are no legal moves left in the game, check number of tokens held by each player. Highest banner token player wins. -See my previous python implementation of the game at https://raw.githubusercontent.com/captn3m0/gothok \ No newline at end of file +See my previous python implementation of the game at https://github.com/captn3m0/gothok/ diff --git a/gothok/game.py b/gothok/game.py index ec731a0..e6d7fbc 100644 --- a/gothok/game.py +++ b/gothok/game.py @@ -3,6 +3,8 @@ import capnp import state_capnp as game +# https://blog.theofekfoundation.org/artificial-intelligence/2016/06/27/what-is-the-monte-carlo-tree-search/ + class State(): @@ -20,6 +22,34 @@ class State(): self.initBoard() pass + def playMove(self, move): + (xx, yy) = move + + varys = self.findVarys + vx = varys.board.x + vy = varys.board.y + + if (vx == xx): + left = min(yy, vy) + right = max(yy, vy) + # We want this to be inclusive + cards_attempted = [(vx, y) for y in range(left, right + 1)] + elif(vy == yy): + top = min(xx, vx) + bottom = max(xx, vx) + # We want this to be inclusive + cards_attempted = [(x, vy) for x in range(top, bottom + 1)] + else: + raise Exception("Invalid move") + + for (row, col) in cards_attempted: + card = self.board[row][col] + # If it is of the same house as declared + if (card == picked_card): + # Pick it up + state['cards'][current].append(picked_card) + state['board'][row][col] = self.EMPTY + def findVarys(self): for card in self.state.cardlist: if card.house == 'varys': @@ -30,7 +60,6 @@ class State(): for x in range(0, 5): for y in range(0, 5): - if (self.isLegalMoveLocation(x, y)): moves.append((x, y)) @@ -118,7 +147,7 @@ class GameNode(object): while not state.gameOver: moves = state.getPossibleMoves() randomMove = random.choice(possibleMoves) - state.playMove(randomMove) + state = state.playMove(randomMove) return self.state.result(state)