def test_queen_at_h8_and_can_move_to_H_and_8_and_diagonal_a1_to_h8(self):
     board = Board(False)
     board.load_fen("7Q/8/8/8/8/8/8/8 w kQkq - 0 1")
     pos = (7, 7)
     possible_moves = moves(
         pos,
         [
             (0, 0),
             (1, 1),
             (2, 2),
             (3, 3),
             (4, 4),
             (5, 5),
             (6, 6),
             (7, 0),
             (7, 1),
             (7, 2),
             (7, 3),
             (7, 4),
             (7, 5),
             (7, 6),
             (0, 7),
             (1, 7),
             (2, 7),
             (3, 7),
             (4, 7),
             (5, 7),
             (6, 7),
         ],
     )
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
    def test_create_board_new_game_true(self):
        board = Board(True)
        # Pawn
        for x in xrange(8):
            self.assertEqual(board.at((x, 6)), BP)
            self.assertEqual(board.at((x, 1)), WP)

        # Rook
        self.assertEqual(board.at((0, 0)), WR)
        self.assertEqual(board.at((7, 0)), WR)
        self.assertEqual(board.at((0, 7)), BR)
        self.assertEqual(board.at((7, 7)), BR)

        # Knight
        self.assertEqual(board.at((1, 0)), WN)
        self.assertEqual(board.at((6, 0)), WN)
        self.assertEqual(board.at((1, 7)), BN)
        self.assertEqual(board.at((6, 7)), BN)

        # Bishop
        self.assertEqual(board.at((2, 0)), WB)
        self.assertEqual(board.at((5, 0)), WB)
        self.assertEqual(board.at((2, 7)), BB)
        self.assertEqual(board.at((5, 7)), BB)

        # Queen
        self.assertEqual(board.at((3, 0)), WQ)
        self.assertEqual(board.at((3, 7)), BQ)

        # King
        self.assertEqual(board.at((4, 0)), WK)
        self.assertEqual(board.at((4, 7)), BK)
 def test_moves_in_a_new_game(self):
     board = Board(True)
     expected_moves_white = set([
         ((0, 1), (0, 2)), ((0, 1), (0, 3)),
         ((1, 1), (1, 2)), ((1, 1), (1, 3)),
         ((2, 1), (2, 2)), ((2, 1), (2, 3)),
         ((3, 1), (3, 2)), ((3, 1), (3, 3)),
         ((4, 1), (4, 2)), ((4, 1), (4, 3)),
         ((5, 1), (5, 2)), ((5, 1), (5, 3)),
         ((6, 1), (6, 2)), ((6, 1), (6, 3)),
         ((7, 1), (7, 2)), ((7, 1), (7, 3)),
         ((1, 0), (0, 2)), ((1, 0), (2, 2)),
         ((6, 0), (5, 2)), ((6, 0), (7, 2)),
     ])
     expected_moves_black = set([
         ((0, 6), (0, 5)), ((0, 6), (0, 4)),
         ((1, 6), (1, 5)), ((1, 6), (1, 4)),
         ((2, 6), (2, 5)), ((2, 6), (2, 4)),
         ((3, 6), (3, 5)), ((3, 6), (3, 4)),
         ((4, 6), (4, 5)), ((4, 6), (4, 4)),
         ((5, 6), (5, 5)), ((5, 6), (5, 4)),
         ((6, 6), (6, 5)), ((6, 6), (6, 4)),
         ((7, 6), (7, 5)), ((7, 6), (7, 4)),
         ((1, 7), (0, 5)), ((1, 7), (2, 5)),
         ((6, 7), (5, 5)), ((6, 7), (7, 5)),
     ])
     self.assertEqual(tuples(board.possible_moves(WHITE)),
                      expected_moves_white)
     self.assertEqual(tuples(board.possible_moves(BLACK)),
                      expected_moves_black)
 def test_queen_at_a1_and_can_move_to_A_and_1_and_diagonal_a1_to_h8(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/Q7 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(
         pos,
         [
             (1, 1),
             (2, 2),
             (3, 3),
             (4, 4),
             (5, 5),
             (6, 6),
             (7, 7),
             (0, 1),
             (0, 2),
             (0, 3),
             (0, 4),
             (0, 5),
             (0, 6),
             (0, 7),
             (1, 0),
             (2, 0),
             (3, 0),
             (4, 0),
             (5, 0),
             (6, 0),
             (7, 0),
         ],
     )
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_rook_at_a1_with_ally_in_b1_can_move_to_all_A(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/RR6 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_rook_at_h8_with_allies_in_f8_and_h6_can_move_to_g8_and_h7(self):
     board = Board(False)
     board.load_fen("5R1R/8/7R/8/8/8/8/8 w kQkq - 0 1")
     pos = (7, 7)
     possible_moves = moves(pos, [
         (6, 7), (7, 6)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_knight_can_move_to_protect_the_king2(self):
     board = Board(False)
     board.load_fen("8/8/8/4N3/2q1K3/8/8/8 w kQkq - 0 1")
     pos = (4, 4)
     possible_moves = moves(pos, [
         (2, 3)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_knight_can_move_if_it_doesnt_protect_the_king(self):
     board = Board(False)
     board.load_fen("8/8/8/4N3/8/8/3K4/8 w kQkq - 0 1")
     pos = (4, 4)
     possible_moves = moves(pos, [
         (3, 2), (5, 2), (6, 3), (6, 5), (5, 6), (3, 6), (2, 5), (2, 3)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_knight_at_a1_and_ally_at_c2_can_move_to_1_position(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/2N5/N7 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (1, 2)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_knight_at_a1_can_move_to_2_positions(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/N7 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (2, 1), (1, 2)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_knight_at_e5_can_move_to_8_positions(self):
     board = Board(False)
     board.load_fen("8/8/8/4N3/8/8/8/8 w kQkq - 0 1")
     pos = (4, 4)
     possible_moves = moves(pos, [
         (3, 2), (5, 2), (6, 3), (6, 5), (5, 6), (3, 6), (2, 5), (2, 3)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_B_at_a1_and_an_b_at_e5_can_move_to_b2_and_c3_and_d4_and_e5(self):
     board = Board(False)
     board.load_fen("8/8/8/4b3/8/8/8/B7 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (1, 1), (2, 2), (3, 3), (4, 4)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_bishop_at_a8_can_move_in_diagonal_a8_to_h1(self):
     board = Board(False)
     board.load_fen("B7/8/8/8/8/8/8/8 w kQkq - 0 1")
     pos = (0, 7)
     possible_moves = moves(pos, [
         (1, 6), (2, 5), (3, 4), (4, 3), (5, 2), (6, 1), (7, 0)
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_rook_at_a1_with_ally_in_a2_can_move_to_all_1(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/R7/R7 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_bishop_at_h8_can_move_in_diagonal_a1_to_g7(self):
     board = Board(False)
     board.load_fen("7B/8/8/8/8/8/8/8 w kQkq - 0 1")
     pos = (7, 7)
     possible_moves = moves(pos, [
         (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_bishop_at_e5_surround_by_allies_distance_2(self):
     board = Board(False)
     board.load_fen("8/2B3B1/8/4B3/8/2B3B1/8/8 w kQkq - 0 1")
     pos = (4, 4)
     possible_moves = moves(pos, [
         (3, 3), (5, 5),
         (3, 5), (5, 3),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_bishop_at_e5_can_move_in_diagonals_a1_to_h8_and_b8_to_h2(self):
     board = Board(False)
     board.load_fen("8/8/8/4B3/8/8/8/8 w kQkq - 0 1")
     pos = (4, 4)
     possible_moves = moves(pos, [
         (0, 0), (1, 1), (2, 2), (3, 3), (5, 5), (6, 6), (7, 7),
         (1, 7), (2, 6), (3, 5), (5, 3), (6, 2), (7, 1),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_moves_that_keeps_check_are_not_allowed(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/4P3/r3K3 w kQkq - 0 1")
     expected_moves_white = set([
         ((4, 0), (3, 1)),
         ((4, 0), (5, 1)),
     ])
     self.assertEqual(tuples(board.possible_moves(WHITE)),
                      expected_moves_white)
 def test_R_at_a1_can_move_to_all_A_and_1(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/R7 w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7),
         (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_R_at_H8_can_move_to_all_H_and_8(self):
     board = Board(False)
     board.load_fen("7R/8/8/8/8/8/8/8 w kQkq - 0 1")
     pos = (7, 7)
     possible_moves = moves(pos, [
         (7, 0), (7, 1), (7, 2), (7, 3), (7, 4), (7, 5), (7, 6),
         (0, 7), (1, 7), (2, 7), (3, 7), (4, 7), (5, 7), (6, 7),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_piece_attack_moves(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/p7/8/R3P3 b kQkq d3 0 1")
     expected_moves_white = set([
         ((0, 0), (0, 1)), ((0, 0), (0, 2)), 
         ((0, 0), (1, 0)), ((0, 0), (2, 0)), ((0, 0), (3, 0)),
     ])
     self.assertEqual(tuples(board.piece_attack_moves((0, 0))),
                      expected_moves_white)
 def test_R_at_e5_can_move_to_all_E_and_5(self):
     board = Board(False)
     board.load_fen("8/8/8/4R3/8/8/8/8 w kQkq - 0 1")
     pos = (4, 4)
     possible_moves = moves(pos, [
         (4, 0), (4, 1), (4, 2), (4, 3), (4, 5), (4, 6), (4, 7),
         (0, 4), (1, 4), (2, 4), (3, 4), (5, 4), (6, 4), (7, 4),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_hindered_in_a_board_with_just_a_knight(self):
     board = Board(False)
     board.load_fen("8/8/8/4N3/8/8/8/8 w kQkq - 0 1")
     expected_hindered_white = set([
         (3, 2), (5, 2), (6, 3), (6, 5), (5, 6), (3, 6), (2, 5), (2, 3)
     ])
     expected_hindered_black = set()
     self.assertEqual(board.hindered(WHITE), expected_hindered_white)
     self.assertEqual(board.hindered(BLACK), expected_hindered_black)
     self.assertEqual(board.hindered(-1), expected_hindered_white)
 def test_R_at_a1_and_r_at_d1_and_a4_cmup_to_enemy_position_including(self):
     board = Board(False)
     board.load_fen("8/8/8/8/r7/8/8/R2r w kQkq - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [
         (0, 1), (0, 2),
         (1, 0), (2, 0),
         (0, 3), (3, 0),
     ])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
 def test_get_pieces(self):
     board = Board(False)
     board.load_fen("8/8/8/5R2/5p2/8/8/8 w kQkq - 0 1")
     pieces = board.get_pieces()
     self.assertEqual(pieces[0].name, "rook")
     self.assertEqual(pieces[0].color, "white")
     self.assertEqual(pieces[0].position, (5, 4))
     self.assertEqual(pieces[1].name, "pawn")
     self.assertEqual(pieces[1].color, "black")
     self.assertEqual(pieces[1].position, (5, 3))
 def test_hindered_in_a_new_game(self):
     board = Board(True)
     expected_hindered_white = set([
         (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2)
     ])
     expected_hindered_black = set([
         (0, 5), (1, 5), (2, 5), (3, 5), (4, 5), (5, 5), (6, 5), (7, 5)
     ])
     self.assertEqual(board.hindered(WHITE), expected_hindered_white)
     self.assertEqual(board.hindered(BLACK), expected_hindered_black)
     self.assertEqual(board.hindered(-1), expected_hindered_white)
 def test_en_passant_killing_moves(self):
     board = Board(False)
     board.load_fen("8/8/8/8/2pP4/8/7P/8 b kQkq d3 0 1")
     expected_moves_white = set()
     expected_moves_black = set([
         ((2, 3), (3, 2)),
     ])
     self.assertEqual(tuples(board.possible_killing_moves(WHITE)),
                      expected_moves_white)
     self.assertEqual(tuples(board.possible_killing_moves(BLACK)),
                      expected_moves_black)
    def test_moves_that_allows_check_are_not_allowed(self):
        board = Board(False)
        board.load_fen("8/8/8/8/7b/8/5P2/4K3 w - - 0 1")
        expected_moves_white = set([
            ((4, 0), (3, 0)),
            ((4, 0), (3, 1)),
            ((4, 0), (5, 0)),
            ((4, 0), (4, 1)),

        ])
        self.assertEqual(tuples(board.possible_moves(WHITE)),
                         expected_moves_white)
 def test_capture_killing_moves(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/2p5/3P3P/8 w kQkq - 0 1")
     expected_moves_white = set([
         ((3, 1), (2, 2)),
     ])
     expected_moves_black = set([
         ((2, 2), (3, 1)),
     ])
     self.assertEqual(tuples(board.possible_killing_moves(WHITE)),
                      expected_moves_white)
     self.assertEqual(tuples(board.possible_killing_moves(BLACK)),
                      expected_moves_black)
 def test_left_en_passant_move(self):
     board = Board(False)
     board.load_fen("8/3p4/8/4P3/8/8/8/8 b kQkq - 0 1")
     self.assertEqual(True, bool(board.move((3, 6), (3, 4), 5)))
     self.assertEqual(board.at((4, 4)), WP)
     self.assertEqual(board.at((3, 4)), BP)
     self.assertEqual(True, bool(board.move((4, 4), (3, 5), 5)))
     self.assertEqual(board.at((4, 4)), None)
     self.assertEqual(board.at((3, 5)), WP)
     self.assertEqual(board.at((3, 4)), None)