コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
 def test_black_pawn_at_e2_with_enemy_at_f1_should_be_promoted_at_f1(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/4p3/5P2 b kQkq f3 0 1")
     pos = (4, 1)
     possible_moves = moves(pos, [(4, 0), (5, 0)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
     board.move((4, 1), (5, 0), 5)
     self.assertEqual(board.at((5, 0)), "black queen")
コード例 #4
0
 def test_white_pawn_at_e7_with_enemy_at_f8_should_be_promoted_at_f8(self):
     board = Board(False)
     board.load_fen("5p2/4P3/8/8/8/8/8/8 w kQkq f3 0 1")
     pos = (4, 6)
     possible_moves = moves(pos, [(4, 7), (5, 7)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
     board.move((4, 6), (5, 7), 5)
     self.assertEqual(board.at((5, 7)), "white queen")
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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)
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #14
0
 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)
コード例 #15
0
 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)
コード例 #16
0
 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)
コード例 #17
0
 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)
コード例 #18
0
 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)
コード例 #19
0
 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)
コード例 #20
0
 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)
コード例 #21
0
 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)
コード例 #22
0
 def test_queen_at_e5_and_can_move_to_E_and_5_diag_a1_h8_and_b8_h2(self):
     board = Board(False)
     board.load_fen("8/8/8/4Q3/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),
             (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)
コード例 #23
0
 def test_king_at_a1_and_allies_at_a2_and_b1_and_b2_no_moves(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/PP6/KP6 w - - 0 1")
     pos = (0, 0)
     possible_moves = set()
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #24
0
 def test_rook_at_e5_surrounded_by_allies_should_have_no_moves(self):
     board = Board(False)
     board.load_fen("8/8/4R3/3RRR2/4R3/8/8/8 w kQkq - 0 1")
     pos = (7, 7)
     possible_moves = set()
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #25
0
 def test_king_at_a1_and_enemy_at_c1_can_move_to_a2(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/K1k5 w - - 0 1")
     pos = (0, 0)
     possible_moves = moves(pos, [(0, 1)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #26
0
 def test_king_at_a2_and_enemy_rook_at_a8_cannot_move_to_a1(self):
     board = Board(False)
     board.load_fen("r7/8/8/8/8/8/K8/8 w - - 0 1")
     pos = (0, 1)
     possible_moves = moves(pos, [(1, 2), (1, 1), (1, 0)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #27
0
 def test_kingside_white_castling(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/4K2R w K - 0 1")
     pos = (4, 0)
     possible_moves = moves(pos, [(3, 0), (3, 1), (4, 1), (5, 1), (5, 0), (6, 0)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #28
0
 def test_kingside_white_castling_is_not_possible_if_there_is_piece2(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/4KR1R w K - 0 1")
     pos = (4, 0)
     possible_moves = moves(pos, [(3, 0), (3, 1), (4, 1), (5, 1)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #29
0
 def test_kingside_white_castling_is_not_possible_if_rook_has_moved(self):
     board = Board(False)
     board.load_fen("8/8/8/8/8/8/8/R3K2R w Q - 0 1")
     pos = (4, 0)
     possible_moves = moves(pos, [(3, 0), (3, 1), (4, 1), (5, 1), (5, 0), (2, 0)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)
コード例 #30
0
 def test_kingside_white_castling_is_not_possible_if_final_hindered(self):
     board = Board(False)
     board.load_fen("6r1/8/8/8/8/8/8/4K2R w K - 0 1")
     pos = (4, 0)
     possible_moves = moves(pos, [(3, 0), (3, 1), (4, 1), (5, 1), (5, 0)])
     self.assertEqual(tuples(board.piece_moves(pos)), possible_moves)