def setUp(self): # We don't bother about closing files, since they are just part of the test warnings.simplefilter("ignore", ResourceWarning) self.perft_file = os.path.join(os.path.dirname(__file__), 'tests/queen.fen') test_trees = [ tools.expand_position(tools.parseFEN(tools.parseEPD(line)[0])) for line in open(self.perft_file) ] self.positions = list( itertools.chain( *[tools.flatten_tree(tree, depth=2) for tree in test_trees]))
def test_fen2(self): initial = sunfish.Position(sunfish.initial, 0, (True,True), (True,True), 0, 0) for pos in tools.flatten_tree(tools.expand_position(initial),3): fen = tools.renderFEN(pos) self.assertEqual(fen.split()[1], 'wb'[tools.get_color(pos)], "Didn't read color correctly") pos1 = tools.parseFEN(fen) self.assertEqual(pos.board, pos1.board, "Sunfish didn't correctly reproduce the board") self.assertEqual(pos.wc, pos1.wc) self.assertEqual(pos.bc, pos1.bc) ep = pos.ep if not pos.board[pos.ep].isspace() else 0 ep1 = pos1.ep if not pos1.board[pos1.ep].isspace() else 0 kp = pos.kp if not pos.board[pos.kp].isspace() else 0 kp1 = pos1.kp if not pos1.board[pos1.kp].isspace() else 0 self.assertEqual(ep, ep1) self.assertEqual(kp, kp1)
def test_fen2(self): initial = sunfish.Position(sunfish.initial, 0, (True, True), (True, True), 0, 0) for pos in tools.flatten_tree(tools.expand_position(initial), 3): fen = tools.renderFEN(pos) self.assertEqual(fen.split()[1], 'wb'[tools.get_color(pos)], "Didn't read color correctly") pos1 = tools.parseFEN(fen) self.assertEqual(pos.board, pos1.board, "Sunfish didn't correctly reproduce the board") self.assertEqual(pos.wc, pos1.wc) self.assertEqual(pos.bc, pos1.bc) ep = pos.ep if not pos.board[pos.ep].isspace() else 0 ep1 = pos1.ep if not pos1.board[pos1.ep].isspace() else 0 kp = pos.kp if not pos.board[pos.kp].isspace() else 0 kp1 = pos1.kp if not pos1.board[pos1.kp].isspace() else 0 self.assertEqual(ep, ep1) self.assertEqual(kp, kp1)
def setUp(self): # We don't bother about closing files, since they are just part of the test warnings.simplefilter("ignore", ResourceWarning) self.perft_file = os.path.join(os.path.dirname(__file__), 'tests/queen.fen') test_trees = [tools.expand_position(tools.parseFEN(tools.parseEPD(line)[0])) for line in open(self.perft_file)] self.positions = list(itertools.chain(*[tools.flatten_tree(tree, depth=2) for tree in test_trees]))