示例#1
0
    def test_castling_out_of_check(self):
        game = Game('4rk2/8/8/8/8/8/8/R3K2R w KQ - 0 1')

        self.assertSetEqual(game.board.check_status(), set("w"))
        self.assertNotIn(BoardSquare('c1'), game.valid_ends('e1'), 'Attempting to castle out of check')
        self.assertNotIn(BoardSquare('g1'), game.valid_ends('e1'), 'Attempting to castle out of check')
        self.assertSetEqual(game.valid_ends('e1'), self._squarify(['d2', 'f2', 'd1', 'f1']))
示例#2
0
    def test_en_passant_taking(self):
        game = Game('rnbqkbnr/pppppppp/8/8/p7/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')

        game = game.move(BasicMove('b2', 'b4'))
        self.assertEqual(game.en_passant, BoardSquare('b3'))
        game = game.move(BasicMove('a4', 'b3'))
        self.assertEqual(game.en_passant, None)
        self.assertEqual(game.board.piece_at_board_square(BoardSquare('b4')), None)
示例#3
0
    def test_en_passant_updating(self):
        game = Game(self.STARTING_FEN)

        self.assertEqual(game.en_passant, None)
        game = game.move(BasicMove('e2', 'e4'))
        self.assertEqual(game.en_passant, BoardSquare('e3'))
        game = game.move(BasicMove('c7', 'c5'))
        self.assertEqual(game.en_passant, BoardSquare('c6'))
        game = game.move(BasicMove('g1', 'f3'))
        self.assertEqual(game.en_passant, None)
        game = game.move(BasicMove('a7', 'a5'))
        self.assertEqual(game.en_passant, BoardSquare('a6'))
示例#4
0
    def test_square_adjustments(self):
        sq = BoardSquare('c3')

        self.assertEqual(sq.delta(1, 1), BoardSquare('d4'))
        self.assertIsNone(sq.delta(10, 10))
        self.assertIsNone(sq.delta(-10, -10))
        self.assertEqual(sq.delta(-1, -1), BoardSquare('b2'))
示例#5
0
    def test_squares(self):
        BoardSquare('e5')
        BoardSquare('a1')
        BoardSquare('c3')
        BoardSquare('g2')

        def expect_fail(file_rank):
            try:
                BoardSquare(file_rank)
                self.fail("BoardSquare expected to have thrown InvalidSquareException for %s%d" % (file, rank))
            except InvalidSquareException:
                pass

        expect_fail('z1')
        expect_fail('a0')
示例#6
0
    def test_valid_ends(self):
        game = Game()

        self.assertSetEqual(game.valid_ends('a1'), set())
        self.assertSetEqual(game.valid_ends('a2'), self._squarify({'a3', 'a4'}))
        self.assertSetEqual(game.valid_ends('b2'), self._squarify({'b3', 'b4'}))
        self.assertSetEqual(game.valid_ends('b1'), self._squarify({'a3', 'c3'}))
        self.assertSetEqual(game.valid_ends('c1'), set())
        self.assertSetEqual(Game(self.SIMPLE_BISHOP_FEN).valid_ends('d1'),
                {BoardSquare('c2'),
                 BoardSquare('b3'),
                 BoardSquare('a4'),
                 BoardSquare('e2'),
                 BoardSquare('f3'),
                 BoardSquare('g4'),
                 BoardSquare('h5')})
示例#7
0
 def f(file_rank):
     sq = BoardSquare(file_rank)
     return game.board.piece_at_board_square(sq)
示例#8
0
 def expect_fail(file_rank):
     try:
         BoardSquare(file_rank)
         self.fail("BoardSquare expected to have thrown InvalidSquareException for %s%d" % (file, rank))
     except InvalidSquareException:
         pass
示例#9
0
 def _squarify(self, square_strs):
     return set([BoardSquare(square_str) for square_str in square_strs])