示例#1
0
    def test_blocked_moves(self):
        position = [[(QUEEN, WHITE), (TOWER, WHITE), None, None, None, None,
                     None, None],
                    [None, (TOWER, WHITE), None, None, None, None, None, None],
                    [(TOWER, WHITE), None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)
        moves = chess_position._get_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 1, moves)
        move = moves[0]
        self.assertExistsPiece(move, (QUEEN, WHITE), 1, 0)
        position = [[
            (QUEEN, WHITE), (TOWER, WHITE), None, None, None, None, None, None
        ], [(TOWER, WHITE), None, None, None, None, None, None,
            None], [None, None, (BISHOP, WHITE), None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)

        moves = chess_position._get_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 1, moves)
        move = moves[0]
        self.assertExistsPiece(move, (QUEEN, WHITE), 1, 1)
示例#2
0
    def test_blocked_moves(self):
        position = [
            [(QUEEN, WHITE), (TOWER, WHITE), None, None, None, None, None, None],
            [None, (TOWER, WHITE), None, None, None, None, None, None],
            [(TOWER, WHITE), None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)
        moves = chess_position._get_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 1, moves)
        move = moves[0]
        self.assertExistsPiece(move, (QUEEN, WHITE), 1, 0)
        position = [
            [(QUEEN, WHITE), (TOWER, WHITE), None, None, None, None, None, None],
            [(TOWER, WHITE), None, None, None, None, None, None, None],
            [None, None, (BISHOP, WHITE), None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)

        moves = chess_position._get_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 1, moves)
        move = moves[0]
        self.assertExistsPiece(move, (QUEEN, WHITE), 1, 1)
示例#3
0
 def test_king_castle(self):
     position = self.fen_to_board('r3k2r/pppppp1p/6Q1/8/8/8/PPPPPPPP/RNB1KBNR')
     chess_position = ChessPosition(position, 1)
     king_moves = chess_position._get_moves(position[0][4], 0, 4)
     self.assertEquals(len(king_moves), 3)
     castle_move = king_moves[2]
     self.assertExistsPiece(castle_move, (KING, WHITE), 0, 2)
     self.assertExistsPiece(castle_move, (TOWER, WHITE), 0, 3)
示例#4
0
 def test_king_castle(self):
     position = self.fen_to_board(
         'r3k2r/pppppp1p/6Q1/8/8/8/PPPPPPPP/RNB1KBNR')
     chess_position = ChessPosition(position, 1)
     king_moves = chess_position._get_moves(position[0][4], 0, 4)
     self.assertEquals(len(king_moves), 3)
     castle_move = king_moves[2]
     self.assertExistsPiece(castle_move, (KING, WHITE), 0, 2)
     self.assertExistsPiece(castle_move, (TOWER, WHITE), 0, 3)
示例#5
0
    def test_all_side_moves(self):
        position = [
            [None, None, None, None, None, None, None, None],
            [None, (TOWER, BLACK), (TOWER, BLACK), (TOWER, BLACK), None, None, None, None],
            [None, (TOWER, BLACK), (QUEEN, WHITE), (TOWER, BLACK), None, None, None, None],
            [None, (TOWER, BLACK), (TOWER, BLACK), (TOWER, BLACK), None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)

        moves = chess_position._get_moves(position[2][2], 2, 2)
        self.assertEquals(len(moves), 8, moves)
示例#6
0
 def test_do_not_put_king_in_mate(self):
     position = [
         [(KING, WHITE), (BISHOP, WHITE), None, None, None, None, None, None],
         [None, (QUEEN, BLACK), None, None, None, None, None, None],
         [(TOWER, WHITE), None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_moves(position[0][0], 0, 0)
     self.assertEquals(len(moves), 1, moves)
     move = moves[0]
     self.assertExistsPiece(move, (KING, WHITE), 1, 1)
示例#7
0
 def test_do_not_put_king_in_mate(self):
     position = [[(KING, WHITE), (BISHOP, WHITE), None, None, None, None,
                  None, None],
                 [None, (QUEEN, BLACK), None, None, None, None, None, None],
                 [(TOWER, WHITE), None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_moves(position[0][0], 0, 0)
     self.assertEquals(len(moves), 1, moves)
     move = moves[0]
     self.assertExistsPiece(move, (KING, WHITE), 1, 1)
示例#8
0
    def test_all_side_moves(self):
        position = [[None, None, None, None, None, None, None, None],
                    [
                        None, (TOWER, BLACK), (TOWER, BLACK), (TOWER, BLACK),
                        None, None, None, None
                    ],
                    [
                        None, (TOWER, BLACK), (QUEEN, WHITE), (TOWER, BLACK),
                        None, None, None, None
                    ],
                    [
                        None, (TOWER, BLACK), (TOWER, BLACK), (TOWER, BLACK),
                        None, None, None, None
                    ], [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)

        moves = chess_position._get_moves(position[2][2], 2, 2)
        self.assertEquals(len(moves), 8, moves)
示例#9
0
 def test_king_no_castle_under_attack(self):
     position = self.fen_to_board('r3k2r/1ppppp1p/R5Q1/8/8/8/PPPPPPPP/1NB1KBNR')
     chess_position = ChessPosition(position, 1)
     king_moves = chess_position._get_moves(position[0][4], 0, 4)
     self.assertEquals(len(king_moves), 2)
示例#10
0
 def test_king_bug(self):
     position = self.fen_to_board('n1n5/PPPk4/8/8/8/8/4Kppp/5N1N')
     chess_position = ChessPosition(position, 2)
     king_moves = chess_position._get_moves(position[6][4], 6, 4)
     self.assertEquals(len(king_moves), 6)
示例#11
0
 def test_king_no_castle_under_attack(self):
     position = self.fen_to_board(
         'r3k2r/1ppppp1p/R5Q1/8/8/8/PPPPPPPP/1NB1KBNR')
     chess_position = ChessPosition(position, 1)
     king_moves = chess_position._get_moves(position[0][4], 0, 4)
     self.assertEquals(len(king_moves), 2)
示例#12
0
 def test_king_bug(self):
     position = self.fen_to_board('n1n5/PPPk4/8/8/8/8/4Kppp/5N1N')
     chess_position = ChessPosition(position, 2)
     king_moves = chess_position._get_moves(position[6][4], 6, 4)
     self.assertEquals(len(king_moves), 6)