Start writing tests (again!)

This commit is contained in:
Nemo 2018-06-01 19:38:33 +05:30
parent c443081083
commit b36e3a3367
2 changed files with 48 additions and 7 deletions

View File

@ -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())

22
gothok/move_test.py Normal file
View File

@ -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)]))