Start writing tests (again!)
This commit is contained in:
parent
c443081083
commit
b36e3a3367
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import capnp
|
import capnp
|
||||||
import state_capnp as game
|
import state_capnp as game
|
||||||
from mcts import GameNode
|
from mcts import GameNode
|
||||||
|
@ -23,6 +24,20 @@ class State():
|
||||||
self.initBoard()
|
self.initBoard()
|
||||||
pass
|
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):
|
def playMove(self, move):
|
||||||
(xx, yy) = move
|
(xx, yy) = move
|
||||||
picked_card = self.board[xx][yy]
|
picked_card = self.board[xx][yy]
|
||||||
|
@ -50,7 +65,6 @@ class State():
|
||||||
|
|
||||||
for (row, col) in cards_attempted:
|
for (row, col) in cards_attempted:
|
||||||
card = self.board[row][col]
|
card = self.board[row][col]
|
||||||
print(card.house, picked_card.house)
|
|
||||||
# If it is of the same house as declared
|
# If it is of the same house as declared
|
||||||
if (card.house == picked_card.house):
|
if (card.house == picked_card.house):
|
||||||
# Pick it up
|
# Pick it up
|
||||||
|
@ -59,6 +73,7 @@ class State():
|
||||||
empty_card.house = game.House.empty
|
empty_card.house = game.House.empty
|
||||||
self.board[row][col] = empty_card
|
self.board[row][col] = empty_card
|
||||||
|
|
||||||
|
self.display()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def findVarys(self):
|
def findVarys(self):
|
||||||
|
@ -83,6 +98,7 @@ class State():
|
||||||
if (self.isLegalMoveLocation(x, y)):
|
if (self.isLegalMoveLocation(x, y)):
|
||||||
moves.append((x, y))
|
moves.append((x, y))
|
||||||
|
|
||||||
|
print(len(moves))
|
||||||
return moves
|
return moves
|
||||||
|
|
||||||
def isLegalMoveLocation(self, x, y):
|
def isLegalMoveLocation(self, x, y):
|
||||||
|
@ -116,7 +132,7 @@ class State():
|
||||||
seen = {}
|
seen = {}
|
||||||
|
|
||||||
for (xx, yy) in l:
|
for (xx, yy) in l:
|
||||||
print(self.board[xx][yy])
|
# print(self.board[xx][yy])
|
||||||
house = self.board[xx][yy].house
|
house = self.board[xx][yy].house
|
||||||
if str(house) in seen:
|
if str(house) in seen:
|
||||||
return False
|
return False
|
||||||
|
@ -127,8 +143,11 @@ class State():
|
||||||
seen[str(house)] = True
|
seen[str(house)] = True
|
||||||
|
|
||||||
|
|
||||||
f = open('state.bin', 'rb')
|
if(__name__ == "__main__"):
|
||||||
initial_state = game.State.read_packed(f)
|
f = open('state.bin', 'rb')
|
||||||
s = State(initial_state)
|
initial_state = game.State.read_packed(f)
|
||||||
root_node = GameNode(s, None)
|
s = State(initial_state)
|
||||||
print(root_node.chooseChild())
|
s.display()
|
||||||
|
|
||||||
|
root_node = GameNode(s, None)
|
||||||
|
print(root_node.chooseChild())
|
||||||
|
|
|
@ -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)]))
|
Loading…
Reference in New Issue