Ejemplo n.º 1
0
    def test_castling_should_not_be_possible_if_rook_has_moved(self):
        e1_king = King(ChessCoord('E', '1'), white)
        h1_rook = Rook(ChessCoord('H', '1'), white)
        h1_rook.update_coord(ChessCoord('H', '2'))
        pieces = [e1_king, h1_rook]
        inspect_move_result = e1_king.inspect_move(pieces, ChessCoord('G', '1'))

        self.failUnless(inspect_move_result ==
                        CastlingMoveInspectResult(False, False, True, False, None,
                                                  ChessCoord('F', '1')))
Ejemplo n.º 2
0
    def test_castling_should_be_possible_for_white_king_h1_rook(self):
        e1_king = King(ChessCoord('E', '1'), white)
        h1_rook = Rook(ChessCoord('H', '1'), white)
        pieces = [e1_king, h1_rook]
        inspect_move_result = e1_king.inspect_move(pieces,
                                                        ChessCoord('G', '1'))

        self.failUnless(inspect_move_result ==
                        CastlingMoveInspectResult(True, False, True, False, h1_rook,
                                                  ChessCoord('F', '1')))
Ejemplo n.º 3
0
class KingTests(unittest.TestCase):
    def setUp(self):
        chess_coord_white = ChessCoord('E', '6')
        self.king_white = King(chess_coord_white, white)
        chess_coord_black = ChessCoord('G', '5')
        self.king_black = King(chess_coord_black, black)

    def test_constructor_white(self):
        self.failUnless(self.king_white.letter == 'K')
        self.failUnless(self.king_white.chess_coord == ChessCoord('E', '6'))
        self.failUnless(self.king_white.grid_coord == GridCoord(4, 5))
        self.failUnless(self.king_white.colour == white)
        self.failUnless(self.king_white.symbol == '♔')
        self.failUnless(util.compare_lists(self.king_white.move_directions,
                                           directions.move_directions_queen()))

    def test_constructor_black(self):
        self.failUnless(self.king_black.letter == 'K')
        self.failUnless(self.king_black.chess_coord == ChessCoord('G', '5'))
        self.failUnless(self.king_black.grid_coord == GridCoord(6, 4))
        self.failUnless(self.king_black.colour == black)
        self.failUnless(self.king_black.symbol == '♚')
        self.failUnless(util.compare_lists(self.king_black.move_directions,
                                           directions.move_directions_queen()))

    def test_white_king_allowed_to_move_north1_east1(self):
        pieces = []

        move_inspect_result = self.king_white.inspect_move(pieces,
                                                           ChessCoord('F', '7'))

        self.failUnless(move_inspect_result ==
                        MoveInspectResult(True, False, [GridCoord(5, 6)], None))

    def test_white_king_not_allowed_to_move_two_steps(self):
        pieces = []

        move_inspect_result = self.king_white.inspect_move(pieces,
                                                           ChessCoord('E', '4'))

        self.failUnless(move_inspect_result ==
                        MoveInspectResult(False, False, [], None))
Ejemplo n.º 4
0
    def test_castling_invalid_enemy_piece_attacks_square_in_between(self):
        e1_king = King(ChessCoord('E', '1'), white)
        h1_rook = Rook(ChessCoord('H', '1'), white)
        f5_rook = Rook(ChessCoord('F', '5'), black)
        pieces = [e1_king, h1_rook, f5_rook]
        inspect_move_result = e1_king.inspect_move(pieces,
                                                   ChessCoord('G', '1'))

        self.failUnless(inspect_move_result ==
                        CastlingMoveInspectResult(False, False, True, True, h1_rook,
                                                  ChessCoord('F', '1')))
Ejemplo n.º 5
0
    def test_castling_not_possible_if_in_check(self):
        e1_king = King(ChessCoord('E', '1'), white)
        h1_rook = Rook(ChessCoord('H', '1'), white)
        e4_rook_black = Rook(ChessCoord('E', '4'), black)
        pieces = [e1_king, h1_rook, e4_rook_black]
        inspect_move_result = e1_king.inspect_move(pieces,
                                                   ChessCoord('G', '1'))

        self.failUnless(inspect_move_result ==
                        CastlingMoveInspectResult(False, False, True, False, h1_rook,
                                                  ChessCoord('F', '1')))