Esempio n. 1
0
 def test_is_legal_pawn_move(self):
     board = Board()
     assert is_legal_move(board, sq_to_index("e2"), sq_to_index("e3"))
     assert is_legal_move(board, sq_to_index("e2"), sq_to_index("e4"))
     assert not is_legal_move(board, sq_to_index("e2"), sq_to_index("e5"))
     assert not is_legal_move(board, sq_to_index("e2"), sq_to_index("f3"))
     assert is_legal_move(board, sq_to_index("e7"), sq_to_index("e6"))
     assert is_legal_move(board, sq_to_index("e7"), sq_to_index("e5"))
     assert not is_legal_move(board, sq_to_index("e7"), sq_to_index("e4"))
Esempio n. 2
0
 def test_pawn_can_defend(self):
     board = fen_to_board("7k/5p2/8/4B3/8/8/8/K7 w")
     print_board(board)
     assert is_in_check(board, BLACK)
     new_board = gen_successor(Board(board), sq_to_index("f7"),
                               sq_to_index("f6"))
     print_board(new_board)
     assert not is_in_check(new_board, BLACK)
     # it follows that black is not in checkmate
     assert not is_in_checkmate(board, BLACK)
Esempio n. 3
0
 def test_promotions_not_pawn(self):
     board = load_board([[" ", "", "", "", "", "k", "", "K"],
                         ["R", "", "", "", "", " ", "", " "],
                         [" ", "", "", "", "", " ", "", " "],
                         [" ", "", "", "", "", " ", "", " "],
                         [" ", "", "", "", "", " ", "", " "],
                         [" ", "", "", "", "", " ", "", " "],
                         [" ", "", "", "", "", " ", "", " "],
                         [" ", "", "", "", "", " ", "", " "]])
     board = Board()
     assert get_promotions(board, sq_to_index("a7"),
                           sq_to_index("a8")) == []
Esempio n. 4
0
    def test_not_in_mate_1(self):
        board = load_board([[' ', ' ', ' ', ' ', 'r', 'b', 'Q', 'k'],
                            [' ', ' ', ' ', ' ', ' ', ' ', ' ', 'p'],
                            ['p', ' ', ' ', 'p', ' ', 'P', ' ', ' '],
                            [' ', ' ', ' ', ' ', ' ', 'R', ' ', ' '],
                            [' ', ' ', ' ', ' ', 'q', ' ', ' ', 'P'],
                            [' ', 'P', ' ', ' ', 'P', ' ', ' ', ' '],
                            ['P', 'B', ' ', ' ', ' ', ' ', ' ', ' '],
                            [' ', ' ', ' ', ' ', ' ', ' ', 'K', ' ']])

        b2 = gen_successor(Board(board), sq_to_index("h8"), sq_to_index("g8"))
        for row in dump_board(b2):
            print(row)
        assert not is_in_check(b2, BLACK)

        assert not is_in_checkmate(board, BLACK)
        assert not is_in_checkmate(board, WHITE)
        assert not is_in_stalemate(board, BLACK)
        assert not is_in_stalemate(board, WHITE)
        assert not _has_no_legal_moves(board, BLACK)
Esempio n. 5
0
 def test_piece_valid_squares(self):
     board = Board()
     assert [
         sq for sq in get_piece_valid_squares(board, sq_to_index("e1"))
     ] == []
     assert [
         sq for sq in get_piece_valid_squares(board, sq_to_index("d1"))
     ] == []
     assert [
         sq for sq in get_piece_valid_squares(board, sq_to_index("c1"))
     ] == []
     assert [
         sq for sq in get_piece_valid_squares(board, sq_to_index("a1"))
     ] == []
     assert [
         sq for sq in get_piece_valid_squares(board, sq_to_index("a8"))
     ] == []
     assert [
         sq for sq in get_piece_valid_squares(board, sq_to_index("e8"))
     ] == []
     assert sorted(get_piece_valid_squares(board, sq_to_index("e2"))) == \
         sorted([sq_to_index(idx) for idx in ["e3", "e4"]])
def test_piece_list():
    board = Board()
    starter_piece_list = [
        ("a1", "R"),
        ("a2", "P"),
        ("b1", "N"),
        ("b2", "P"),
        ("c1", "B"),
        ("c2", "P"),
        ("d1", "Q"),
        ("d2", "P"),
        ("e1", "K"),
        ("e2", "P"),
        ("f1", "B"),
        ("f2", "P"),
        ("g1", "N"),
        ("g2", "P"),
        ("h1", "R"),
        ("h2", "P"),
    ]
    pl = get_piece_list(board, WHITE)
    apl = [(index_to_sq(idx), piece) for idx, piece in pl]
    assert sorted(apl) == starter_piece_list
Esempio n. 7
0
 def test_king_valid_squares(self):
     board = Board()
     index = sq_to_index("e1")
     assert [sq for sq in get_king_valid_squares(board, index)] == []
     assert [sq for sq in get_king_valid_squares(board, index)] == []
Esempio n. 8
0
 def test_is_in_check_starter_board(self):
     board = Board()
     assert not is_in_check(board, WHITE)
     assert not is_in_check(board, BLACK)
Esempio n. 9
0
 def test_rook_starter_board_valid_squares(self):
     board = Board()
     index = sq_to_index("a1")
     assert [sq for sq in get_rook_valid_squares(board, index)] == []
Esempio n. 10
0
 def test_knight_valid_squares(self):
     board = Board()
     index = sq_to_index("b1")
     knight_sq = sorted([sq_to_index(sq) for sq in ["a3", "c3"]])
     assert sorted(get_knight_valid_squares(board, index)) == knight_sq
Esempio n. 11
0
 def test_pawn_valid_squares(self):
     board = Board()
     index = sq_to_index("e2")
     pawn_sq = sorted([sq_to_index(sq) for sq in ["e3", "e4"]])
     assert sorted(get_pawn_valid_squares(board, index)) == pawn_sq