示例#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_all_side_moves(self):
        position = [[None, None, None, None, None, None, None, None],
                    [
                        None, (BISHOP, BLACK), None, (BISHOP, BLACK), None,
                        None, None, None
                    ],
                    [
                        None, None, (BISHOP, WHITE), None, None, None, None,
                        None
                    ],
                    [
                        None, (BISHOP, BLACK), None, (BISHOP, 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_bishop_moves(position[2][2], 2, 2)
        self.assertEquals(len(moves), 4, moves)
        move = moves[0]
        self.assertExistsPiece(move, (BISHOP, WHITE), 3, 3)
        move = moves[1]
        self.assertExistsPiece(move, (BISHOP, WHITE), 3, 1)
        move = moves[2]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 3)
        move = moves[3]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 1)
示例#3
0
 def test_black_en_passent_moves(self):
     position = [
         [None, None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [(PAWN, BLACK), (PAWN, 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]]
     chess_position = ChessPosition(position, 2, piece_moved=[(1, 1), (3, 1)])
     moves = chess_position._get_pawn_moves(position[3][0], 3, 0)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[2][0], (PAWN, BLACK))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, BLACK), 2, 1)
     position = [
         [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, (PAWN, WHITE), (PAWN, 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]]
     chess_position = ChessPosition(position, 2, piece_moved=[(1, 6), (3, 6)])
     moves = chess_position._get_pawn_moves(position[3][7], 3, 7)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[2][7], (PAWN, BLACK))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, BLACK), 2, 6)
示例#4
0
 def test_promotion_errors(self):
     position = self.fen_to_board('n1n5/PPPk4/8/8/8/8/4Kppp/5N1N')
     chess_position = ChessPosition(position, 1)
     moves = chess_position.get_moves_for_depth(1)
     self.assertEqual(len(moves), 24)
     moves = chess_position.get_moves_for_depth(2)
     self.assertEqual(len(moves), 520)
示例#5
0
    def test_white_pawn_moves(self):
        position = [
            [None, None, None, None, None, None, None, None],
            [None, (PAWN, WHITE), None, None, None, None, None, None],
            [(QUEEN, BLACK), (PAWN, BLACK), (PAWN, 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, 1)
        moves = chess_position._get_pawn_moves(position[1][1], 1, 1)
        self.assertEquals(len(moves), 1, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[1][1], None)
        self.assertEquals(attack_move.position[2][0], (PAWN, WHITE))

        position = [
            [None, None, None, None, None, None, None, None],
            [None, (PAWN, 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, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)
        moves = chess_position._get_pawn_moves(position[1][1], 1, 1)
        self.assertEquals(len(moves), 2, moves)
        attack_move = moves[0]
        self.assertOnlyPiece(attack_move, (PAWN, WHITE), 2, 1)
        attack_move = moves[1]
        self.assertOnlyPiece(attack_move, (PAWN, WHITE), 3, 1)
示例#6
0
    def test_blocked_moves(self):
        position = [
            [(BISHOP, WHITE), None, None, None, None, None, None, None],
            [None, 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_bishop_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 1, moves)
        move = moves[0]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 1)
        position = [
            [(BISHOP, WHITE), None, None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None],
            [None, None, (BISHOP, 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, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)
        moves = chess_position._get_bishop_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 2, moves)
        move = moves[0]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 1)
        move = moves[1]
        self.assertOnlyPiece(move, (BISHOP, WHITE), 2, 2)
示例#7
0
 def test_blocked_moves(self):
     position = [
         [(TOWER, WHITE), (TOWER, WHITE), None, None, None, None, None, None],
         [None, None, 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_tower_moves(position[0][0], 0, 0)
     self.assertEquals(len(moves), 1, moves)
     move = moves[0]
     self.assertExistsPiece(move, (TOWER, WHITE), 1, 0)
     position = [
         [(TOWER, WHITE), (TOWER, WHITE), None, None, None, None, None, None],
         [None, None, None, None, None, None, None, None],
         [(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, None, None, None],
         [None, None, None, None, None, None, None, None]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_tower_moves(position[0][0], 0, 0)
     self.assertEquals(len(moves), 2, moves)
     move = moves[0]
     self.assertExistsPiece(move, (TOWER, WHITE), 1, 0)
     move = moves[1]
     self.assertExistsPiece(move, (TOWER, WHITE), 2, 0)
示例#8
0
 def test_promotion_errors(self):
     position = self.fen_to_board('n1n5/PPPk4/8/8/8/8/4Kppp/5N1N')
     chess_position = ChessPosition(position, 1)
     moves = chess_position.get_moves_for_depth(1)
     self.assertEqual(len(moves), 24)
     moves = chess_position.get_moves_for_depth(2)
     self.assertEqual(len(moves), 520)
示例#9
0
 def test_white_en_passent_moves(self):
     position = [
         [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],
         [(PAWN, WHITE), (PAWN, 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]]
     chess_position = ChessPosition(position, 2, piece_moved=[(6, 1), (4, 1)])
     moves = chess_position._get_pawn_moves(position[4][0], 4, 0)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[5][0], (PAWN, WHITE))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, WHITE), 5, 1)
     position = [
         [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, (PAWN, BLACK), (PAWN, 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]]
     chess_position = ChessPosition(position, 2, piece_moved=[(6, 6), (4, 6)])
     moves = chess_position._get_pawn_moves(position[4][7], 4, 7)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[5][7], (PAWN, WHITE))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, WHITE), 5, 6)
示例#10
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)
示例#11
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)
示例#12
0
 def test_starting_position(self):
     position = self.fen_to_board('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR')
     chess_position = ChessPosition(position, 1)
     moves = chess_position.get_moves_for_depth(1)
     self.assertEqual(len(moves), 20)
     moves = chess_position.get_moves_for_depth(2)
     self.assertEqual(len(moves), 420)
     moves = chess_position.get_moves_for_depth(3)
     self.assertEqual(len(moves), 9322)
示例#13
0
 def test_starting_position(self):
     position = self.fen_to_board(
         'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR')
     chess_position = ChessPosition(position, 1)
     moves = chess_position.get_moves_for_depth(1)
     self.assertEqual(len(moves), 20)
     moves = chess_position.get_moves_for_depth(2)
     self.assertEqual(len(moves), 420)
     moves = chess_position.get_moves_for_depth(3)
     self.assertEqual(len(moves), 9322)
示例#14
0
 def test_blocked_moves(self):
     position = [[None, None, None, (HORSE, WHITE), None, None, None, None],
                 [None, (HORSE, WHITE), None, None, None, None, None, None],
                 [None, None, None, (HORSE, WHITE), None, None, None, None],
                 [None, None, (HORSE, 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]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_knight_moves(position[1][1], 1, 1)
     self.assertEquals(len(moves), 1, moves)
     move = moves[0]
     self.assertExistsPiece(move, (HORSE, WHITE), 3, 0)
示例#15
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)
示例#16
0
 def test_capture_moves(self):
     position = [
         [None, None, None, (HORSE, WHITE), None, None, None, None],
         [None, (HORSE, WHITE), None, None, None, None, None, None],
         [None, None, None, (HORSE, WHITE), None, None, None, None],
         [(HORSE, BLACK), None, (HORSE, 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]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_knight_moves(position[1][1], 1, 1)
     self.assertEquals(len(moves), 1, moves)
     move = moves[0]
     self.assertExistsPiece(move, (HORSE, WHITE), 3, 0)
示例#17
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)
示例#18
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)
示例#19
0
    def test_blocked_moves(self):
        position = [[
            (KING, 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, (KING, WHITE), 1, 1)
示例#20
0
 def test_middle_knight_moves(self):
     position = [[None, None, None, None, None, None, None, None],
                 [None, (HORSE, 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, None, None, None, None, None, None, None]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_knight_moves(position[1][1], 1, 1)
     self.assertEquals(len(moves), 4, moves)
     move = moves[0]
     self.assertOnlyPiece(move, (HORSE, WHITE), 3, 2)
     move = moves[1]
     self.assertOnlyPiece(move, (HORSE, WHITE), 2, 3)
     move = moves[2]
     self.assertOnlyPiece(move, (HORSE, WHITE), 0, 3)
     move = moves[3]
     self.assertOnlyPiece(move, (HORSE, WHITE), 3, 0)
示例#21
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)
示例#22
0
 def test_middle_knight_moves(self):
     position = [
         [None, None, None, None, None, None, None, None],
         [None, (HORSE, 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, None, None, None, None, None, None, None]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_knight_moves(position[1][1], 1, 1)
     self.assertEquals(len(moves), 4, moves)
     move = moves[0]
     self.assertOnlyPiece(move, (HORSE, WHITE), 3, 2)
     move = moves[1]
     self.assertOnlyPiece(move, (HORSE, WHITE), 2, 3)
     move = moves[2]
     self.assertOnlyPiece(move, (HORSE, WHITE), 0, 3)
     move = moves[3]
     self.assertOnlyPiece(move, (HORSE, WHITE), 3, 0)
示例#23
0
    def test_white_pawn_moves(self):
        position = [[None, None, None, None, None, None, None, None],
                    [None, (PAWN, WHITE), None, None, None, None, None, None],
                    [(QUEEN, BLACK), (PAWN, BLACK), (PAWN, 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, 1)
        moves = chess_position._get_pawn_moves(position[1][1], 1, 1)
        self.assertEquals(len(moves), 1, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[1][1], None)
        self.assertEquals(attack_move.position[2][0], (PAWN, WHITE))

        position = [[None, None, None, None, None, None, None, None],
                    [None, (PAWN, 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, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)
        moves = chess_position._get_pawn_moves(position[1][1], 1, 1)
        self.assertEquals(len(moves), 2, moves)
        attack_move = moves[0]
        self.assertOnlyPiece(attack_move, (PAWN, WHITE), 2, 1)
        attack_move = moves[1]
        self.assertOnlyPiece(attack_move, (PAWN, WHITE), 3, 1)
示例#24
0
    def test_blocked_moves(self):
        position = [[
            (BISHOP, WHITE), None, None, None, None, None, None, None
        ], [None, 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_bishop_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 1, moves)
        move = moves[0]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 1)
        position = [[
            (BISHOP, WHITE), None, None, None, None, None, None, None
        ], [None, None, None, None, None, None, None,
            None], [None, None, (BISHOP, 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, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 3)
        moves = chess_position._get_bishop_moves(position[0][0], 0, 0)
        self.assertEquals(len(moves), 2, moves)
        move = moves[0]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 1)
        move = moves[1]
        self.assertOnlyPiece(move, (BISHOP, WHITE), 2, 2)
示例#25
0
 def test_blocked_moves(self):
     position = [[(TOWER, WHITE), (TOWER, WHITE), None, None, None, None,
                  None, None],
                 [None, None, 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_tower_moves(position[0][0], 0, 0)
     self.assertEquals(len(moves), 1, moves)
     move = moves[0]
     self.assertExistsPiece(move, (TOWER, WHITE), 1, 0)
     position = [[(TOWER, WHITE), (TOWER, WHITE), None, None, None, None,
                  None, None],
                 [None, None, None, None, None, None, None, None],
                 [(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, None, None, None],
                 [None, None, None, None, None, None, None, None]]
     chess_position = ChessPosition(position, 3)
     moves = chess_position._get_tower_moves(position[0][0], 0, 0)
     self.assertEquals(len(moves), 2, moves)
     move = moves[0]
     self.assertExistsPiece(move, (TOWER, WHITE), 1, 0)
     move = moves[1]
     self.assertExistsPiece(move, (TOWER, WHITE), 2, 0)
示例#26
0
    def test_black_pawn_moves(self):
        position = [[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],
                    [(PAWN, WHITE), (PAWN, WHITE), (PAWN, WHITE), None, None,
                     None, None, None],
                    [None, (PAWN, BLACK), None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 2, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[6][1], None)
        self.assertEquals(attack_move.position[5][0], (PAWN, BLACK))
        attack_move = moves[1]
        self.assertEquals(attack_move.position[6][1], None)
        self.assertEquals(attack_move.position[5][2], (PAWN, BLACK))

        position = [[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, None],
                    [None, (PAWN, BLACK), None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 1)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 2, moves)
        attack_move = moves[0]
        self.assertOnlyPiece(attack_move, (PAWN, BLACK), 5, 1)
        attack_move = moves[1]
        self.assertOnlyPiece(attack_move, (PAWN, BLACK), 4, 1)
示例#27
0
    def test_all_side_moves(self):
        position = [
            [None, None, None, None, None, None, None, None],
            [None, None, (TOWER, BLACK), None, None, None, None, None],
            [None, (TOWER, BLACK), (TOWER, WHITE), (TOWER, BLACK), None, None, None, None],
            [None, None, (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, None]]
        chess_position = ChessPosition(position, 3)

        moves = chess_position._get_tower_moves(position[2][2], 2, 2)
        self.assertEquals(len(moves), 4, moves)
        move = moves[0]
        self.assertExistsPiece(move, (TOWER, WHITE), 3, 2)
        move = moves[1]
        self.assertExistsPiece(move, (TOWER, WHITE), 2, 3)
        move = moves[2]
        self.assertExistsPiece(move, (TOWER, WHITE), 1, 2)
        move = moves[3]
        self.assertExistsPiece(move, (TOWER, WHITE), 2, 1)
示例#28
0
    def test_all_side_moves(self):
        position = [
            [None, None, None, None, None, None, None, None],
            [None, (BISHOP, BLACK), None, (BISHOP, BLACK), None, None, None, None],
            [None, None, (BISHOP, WHITE), None, None, None, None, None],
            [None, (BISHOP, BLACK), None, (BISHOP, 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_bishop_moves(position[2][2], 2, 2)
        self.assertEquals(len(moves), 4, moves)
        move = moves[0]
        self.assertExistsPiece(move, (BISHOP, WHITE), 3, 3)
        move = moves[1]
        self.assertExistsPiece(move, (BISHOP, WHITE), 3, 1)
        move = moves[2]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 3)
        move = moves[3]
        self.assertExistsPiece(move, (BISHOP, WHITE), 1, 1)
示例#29
0
    def test_all_side_moves(self):
        position = [[None, None, None, None, None, None, None, None],
                    [None, None, (TOWER, BLACK), None, None, None, None, None],
                    [
                        None, (TOWER, BLACK), (TOWER, WHITE), (TOWER, BLACK),
                        None, None, None, None
                    ],
                    [None, None, (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, None]]
        chess_position = ChessPosition(position, 3)

        moves = chess_position._get_tower_moves(position[2][2], 2, 2)
        self.assertEquals(len(moves), 4, moves)
        move = moves[0]
        self.assertExistsPiece(move, (TOWER, WHITE), 3, 2)
        move = moves[1]
        self.assertExistsPiece(move, (TOWER, WHITE), 2, 3)
        move = moves[2]
        self.assertExistsPiece(move, (TOWER, WHITE), 1, 2)
        move = moves[3]
        self.assertExistsPiece(move, (TOWER, WHITE), 2, 1)
示例#30
0
    def test_black_pawn_moves(self):
        position = [
            [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],
            [(PAWN, WHITE), (PAWN, WHITE), (PAWN, WHITE), None, None, None, None, None],
            [None, (PAWN, BLACK), None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 2, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[6][1], None)
        self.assertEquals(attack_move.position[5][0], (PAWN, BLACK))
        attack_move = moves[1]
        self.assertEquals(attack_move.position[6][1], None)
        self.assertEquals(attack_move.position[5][2], (PAWN, BLACK))

        position = [
            [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, None],
            [None, (PAWN, BLACK), None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 1)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 2, moves)
        attack_move = moves[0]
        self.assertOnlyPiece(attack_move, (PAWN, BLACK), 5, 1)
        attack_move = moves[1]
        self.assertOnlyPiece(attack_move, (PAWN, BLACK), 4, 1)
示例#31
0
 def test_black_en_passent_moves(self):
     position = [[None, None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None],
                 [None, None, None, None, None, None, None, None],
                 [(PAWN, BLACK), (PAWN, 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]]
     chess_position = ChessPosition(position,
                                    2,
                                    piece_moved=[(1, 1), (3, 1)])
     moves = chess_position._get_pawn_moves(position[3][0], 3, 0)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[2][0], (PAWN, BLACK))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, BLACK), 2, 1)
     position = [[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, (PAWN, WHITE),
                     (PAWN, 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]]
     chess_position = ChessPosition(position,
                                    2,
                                    piece_moved=[(1, 6), (3, 6)])
     moves = chess_position._get_pawn_moves(position[3][7], 3, 7)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[2][7], (PAWN, BLACK))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, BLACK), 2, 6)
示例#32
0
 def test_white_en_passent_moves(self):
     position = [[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],
                 [(PAWN, WHITE), (PAWN, 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]]
     chess_position = ChessPosition(position,
                                    2,
                                    piece_moved=[(6, 1), (4, 1)])
     moves = chess_position._get_pawn_moves(position[4][0], 4, 0)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[5][0], (PAWN, WHITE))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, WHITE), 5, 1)
     position = [[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, (PAWN, BLACK),
                     (PAWN, 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]]
     chess_position = ChessPosition(position,
                                    2,
                                    piece_moved=[(6, 6), (4, 6)])
     moves = chess_position._get_pawn_moves(position[4][7], 4, 7)
     self.assertEquals(len(moves), 2, moves)
     forward_move = moves[0]
     self.assertEquals(forward_move.position[5][7], (PAWN, WHITE))
     en_passent_move = moves[1]
     self.assertOnlyPiece(en_passent_move, (PAWN, WHITE), 5, 6)
示例#33
0
 def test_king_check(self):
     position = self.fen_to_board('k7/Q7/7b/8/8/8/8/8')
     chess_position = ChessPosition(position, 1)
     moves = list(chess_position.get_moves())
     self.assertEqual(len(moves), 1)
示例#34
0
    def test_white_upgrade_moves(self):
        position = [[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, None],
                    [None, (PAWN, WHITE), None, None, None, None, None, None],
                    [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 4, moves)
        attack_move = moves[0]
        self.assertOnlyPiece(attack_move, (HORSE, WHITE), 7, 1)
        attack_move = moves[1]
        self.assertOnlyPiece(attack_move, (BISHOP, WHITE), 7, 1)
        attack_move = moves[2]
        self.assertOnlyPiece(attack_move, (TOWER, WHITE), 7, 1)
        attack_move = moves[3]
        self.assertOnlyPiece(attack_move, (QUEEN, WHITE), 7, 1)

        position = [[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, None],
                    [None, (PAWN, WHITE), None, None, None, None, None, None],
                    [(QUEEN, WHITE), (KING, WHITE), (PAWN, BLACK), None, None,
                     None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 4, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[7][2], (HORSE, WHITE))
        attack_move = moves[1]
        self.assertEquals(attack_move.position[7][2], (BISHOP, WHITE))
        attack_move = moves[2]
        self.assertEquals(attack_move.position[7][2], (TOWER, WHITE))
        attack_move = moves[3]
        self.assertEquals(attack_move.position[7][2], (QUEEN, WHITE))

        position = [[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, None],
                    [None, (PAWN, WHITE), None, None, None, None, None, None],
                    [(QUEEN, BLACK), (KING, WHITE), (HORSE, WHITE), None, None,
                     None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 4, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[7][0], (HORSE, WHITE))
        attack_move = moves[1]
        self.assertEquals(attack_move.position[7][0], (BISHOP, WHITE))
        attack_move = moves[2]
        self.assertEquals(attack_move.position[7][0], (TOWER, WHITE))
        attack_move = moves[3]
        self.assertEquals(attack_move.position[7][0], (QUEEN, WHITE))
示例#35
0
 def test_king_loose(self):
     position = self.fen_to_board('4k3/8/8/8/8/8/8/4K2R')
     chess_position = ChessPosition(position, 2, bc_rights=False)
     moves = list(chess_position.get_moves())
     self.assertEqual(len(moves), 14)
示例#36
0
    def test_white_upgrade_moves(self):
        position = [
            [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, None],
            [None, (PAWN, WHITE), None, None, None, None, None, None],
            [None, None, None, None, None, None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 4, moves)
        attack_move = moves[0]
        self.assertOnlyPiece(attack_move, (HORSE, WHITE), 7, 1)
        attack_move = moves[1]
        self.assertOnlyPiece(attack_move, (BISHOP, WHITE), 7, 1)
        attack_move = moves[2]
        self.assertOnlyPiece(attack_move, (TOWER, WHITE), 7, 1)
        attack_move = moves[3]
        self.assertOnlyPiece(attack_move, (QUEEN, WHITE), 7, 1)

        position = [
            [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, None],
            [None, (PAWN, WHITE), None, None, None, None, None, None],
            [(QUEEN, WHITE), (KING, WHITE), (PAWN, BLACK), None, None, None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 4, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[7][2], (HORSE, WHITE))
        attack_move = moves[1]
        self.assertEquals(attack_move.position[7][2], (BISHOP, WHITE))
        attack_move = moves[2]
        self.assertEquals(attack_move.position[7][2], (TOWER, WHITE))
        attack_move = moves[3]
        self.assertEquals(attack_move.position[7][2], (QUEEN, WHITE))

        position = [
            [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, None],
            [None, (PAWN, WHITE), None, None, None, None, None, None],
            [(QUEEN, BLACK), (KING, WHITE), (HORSE, WHITE), None, None, None, None, None]]
        chess_position = ChessPosition(position, 2)
        moves = chess_position._get_pawn_moves(position[6][1], 6, 1)
        self.assertEquals(len(moves), 4, moves)
        attack_move = moves[0]
        self.assertEquals(attack_move.position[7][0], (HORSE, WHITE))
        attack_move = moves[1]
        self.assertEquals(attack_move.position[7][0], (BISHOP, WHITE))
        attack_move = moves[2]
        self.assertEquals(attack_move.position[7][0], (TOWER, WHITE))
        attack_move = moves[3]
        self.assertEquals(attack_move.position[7][0], (QUEEN, WHITE))
示例#37
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)
示例#38
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)
示例#39
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)
示例#40
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)
示例#41
0
 def test_king_loose(self):
     position = self.fen_to_board('4k3/8/8/8/8/8/8/4K2R')
     chess_position = ChessPosition(position, 2, bc_rights=False)
     moves = list(chess_position.get_moves())
     self.assertEqual(len(moves), 14)
示例#42
0
 def test_king_check(self):
     position = self.fen_to_board('k7/Q7/7b/8/8/8/8/8')
     chess_position = ChessPosition(position, 1)
     moves = list(chess_position.get_moves())
     self.assertEqual(len(moves), 1)