diff --git a/gothok/game.py b/gothok/game.py index 8f02250..82ea180 100644 --- a/gothok/game.py +++ b/gothok/game.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import capnp import state_capnp as game from mcts import GameNode @@ -23,6 +24,20 @@ class State(): self.initBoard() pass + def display(self): + map = { + "empty": " ", "varys": "*", "tully": "U", + "tyrell": "Y", "baratheon": "B", "targaryen": "T", + "lannister": "L", "greyjoy": "G", "stark": "S", + } + for row in self.board: + for card in row: + house = str(card.house) + print(map[house], end='') + print() + + print() + def playMove(self, move): (xx, yy) = move picked_card = self.board[xx][yy] @@ -50,7 +65,6 @@ class State(): for (row, col) in cards_attempted: card = self.board[row][col] - print(card.house, picked_card.house) # If it is of the same house as declared if (card.house == picked_card.house): # Pick it up @@ -59,6 +73,7 @@ class State(): empty_card.house = game.House.empty self.board[row][col] = empty_card + self.display() return self def findVarys(self): @@ -83,6 +98,7 @@ class State(): if (self.isLegalMoveLocation(x, y)): moves.append((x, y)) + print(len(moves)) return moves def isLegalMoveLocation(self, x, y): @@ -116,7 +132,7 @@ class State(): seen = {} for (xx, yy) in l: - print(self.board[xx][yy]) + # print(self.board[xx][yy]) house = self.board[xx][yy].house if str(house) in seen: return False @@ -127,8 +143,11 @@ class State(): seen[str(house)] = True -f = open('state.bin', 'rb') -initial_state = game.State.read_packed(f) -s = State(initial_state) -root_node = GameNode(s, None) -print(root_node.chooseChild()) +if(__name__ == "__main__"): + f = open('state.bin', 'rb') + initial_state = game.State.read_packed(f) + s = State(initial_state) + s.display() + + root_node = GameNode(s, None) + print(root_node.chooseChild()) diff --git a/gothok/move_test.py b/gothok/move_test.py new file mode 100644 index 0000000..48cf45a --- /dev/null +++ b/gothok/move_test.py @@ -0,0 +1,22 @@ +import game +import capnp +import state_capnp + +f = open('state.bin', 'rb') +initial_state = state_capnp.State.read_packed(f) +s = game.State(initial_state) + +# BTBYSL +# LGSYSG +# GTSSSB +# UUT*TG +# LTLGSB +# YGLLSG + + +s.display() + +possible_moves = set(s.getPossibleMoves()) +print(possible_moves) + +assert(possible_moves == set([(3, 0), (0, 3), (3, 4), (4, 3)]))