Пример #1
0
def test_can_castle_init():
    b = main.Board()
    b.init_default()
    assert b.black_can_castle_k
    assert b.black_can_castle_q
    assert b.white_can_castle_k
    assert b.white_can_castle_q
Пример #2
0
def test_cant_castle_q_cause_check_3():
    b = main.Board()
    b.add_piece('k', 'e8', is_white=False)
    b.add_piece('k', 'e1', is_white=True)
    b.add_piece('r', 'a1', is_white=True)
    b.add_piece('q', 'c4', is_white=False)
    assert not b.can_castle_q_white()
def test_pawn_blocked_by_pawn():
    b = main.Board()
    b.add_piece('p', 'd2', True)
    b.add_piece('p', 'd3', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 1
    assert 'd4' in moves
def test_cant_move_if_check():
    b = main.Board()
    b.add_piece('k', 'd4', is_white=True)
    b.add_piece('p', 'c5', is_white=True)
    b.add_piece('b', 'b6', is_white=False)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert 'c6' not in moves
def test_lonely_start_row_pawn_white():
    b = main.Board()
    b.add_piece('p', 'a2', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 2
    assert 'a3' in moves
    assert 'a4' in moves
Пример #6
0
def test_find_king_several():
    b = main.Board()
    b.add_piece('k', 'e4', is_white=True)
    b.add_piece('k', 'e5', is_white=True)
    with pytest.raises(Exception):
        pos = b.get_king_position(white_king=True)
        assert pos == 'e4'
def test_same_target_knights():
    fen = "k4n2/8/8/2n5/8/8/K7/8 b - - 0 1"
    b = main.Board()
    b.init_fen(fen)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert 'Ne6' not in moves
    assert 'Nce6' in moves
    assert 'Nfe6' in moves
Пример #8
0
def test_if_check_have_to_move():
    b = main.Board(white_to_play=False)
    b.add_piece('k', 'e8', is_white=False)
    b.add_piece('p', 'a7', is_white=False)
    b.add_piece('q', 'e1', is_white=True)
    b.add_piece('k', 'h1', is_white=True)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert len(moves) == 4
Пример #9
0
def test_castle_1():
    fen = "r2k1b1r/p1p1pppp/1PP5/8/3P2n1/8/PP3PPP/RNB1K1NR b KQ - 0 10"
    b = main.Board()
    b.init_fen(fen)
    assert not b.black_can_castle_q
    assert not b.black_can_castle_k
    assert b.white_can_castle_k
    assert b.white_can_castle_q
def test_same_target_knights_2():
    fen = "k7/8/3n4/8/3n4/8/K7/8 b - - 0 1"
    b = main.Board()
    b.init_fen(fen)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert 'Nf5' not in moves
    assert 'N4f5' in moves
    assert 'N6f5' in moves
def test_same_col_rooks():
    fen = "k7/6KR/8/8/8/6PR/8/8 w - - 0 1"
    b = main.Board()
    b.init_fen(fen)
    moves = [m.to_string() for m in b.get_possible_moves()]
    print(moves)
    assert 'Rh5' not in moves
    assert 'R7h5' in moves
    assert 'R3h5' in moves
def test_same_row_rooks():
    fen = "k7/8/8/8/8/3R3R/K7/8 w - - 0 1"
    b = main.Board()
    b.init_fen(fen)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert 'Re3' not in moves
    assert 'Rde3' in moves
    assert 'Rhe3' in moves
    assert 'Rd6' in moves
Пример #13
0
def test_can_promote():
    fen = "rnbq3r/ppppkP1p/7n/6p1/4P3/8/PPPB1PPP/RN2KBNR w KQ - 1 8"
    b = main.Board()
    b.init_fen(fen)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert "f8=Q" in moves
    assert "f8=B" in moves
    assert "f8=N" in moves
    assert "f8=R" in moves
def test_lonely_centered_rook_white():
    b = main.Board()
    b.add_piece('r', 'd4', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 14
    assert 'Rd8' in moves
    assert 'Rd5' in moves
    assert 'Rd1' in moves
    assert 'Rh4' in moves
def test_knight_blocked_by_pawn():
    b = main.Board()
    b.add_piece('n', 'a1', True)
    b.add_piece('p', 'c2', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 3
    assert 'c3' in moves
    assert 'c4' in moves
    assert 'Nb3' in moves
Пример #16
0
def test_black_can_promote_by_taking():
    fen = "rnbqkbnr/ppp1pppp/B7/8/3P1P2/8/PPPKp1PP/RNBQ2NR b kq - 1 5"
    b = main.Board()
    b.init_fen(fen)
    moves = [m.to_string() for m in b.get_possible_moves()]
    assert "exd1=Q" in moves
    assert "exd1=B" in moves
    assert "exd1=N" in moves
    assert "exd1=R" in moves
def test_lonely_centered_bishop_white():
    b = main.Board()
    b.add_piece('b', 'd4', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 13
    assert 'Ba7' in moves
    assert 'Bg7' in moves
    assert 'Bh8' in moves
    assert 'Bg1' in moves
Пример #18
0
def test_cant_castle_king_moved():
    b = main.Board()
    b.init_default()
    b.process_move('e4')
    b.process_move('e5')
    b.process_move('Ke2')
    assert b.black_can_castle_k
    assert b.black_can_castle_q
    assert not b.white_can_castle_k
    assert not b.white_can_castle_q
def test_king_blocked_by_pawn():
    b = main.Board()
    b.add_piece('k', 'a1', True)
    b.add_piece('p', 'a2', True)
    b.add_piece('p', 'b1', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 4
    assert 'a3' in moves
    assert 'a4' in moves
    assert 'b2' in moves
def test_bishop_takes_pawn():
    b = main.Board()
    b.add_piece('b', 'a1', is_white=True)
    b.add_piece('p', 'b2', is_white=False)
    moves = b.get_naive_moves(from_white=True)
    moves_san = [m.to_string() for m in moves]
    takes = [m for m in moves if m.is_take]
    assert len(moves) == 1
    assert len(takes) == 1
    assert 'Bxb2' in moves_san
def test_rook_takes_pawn():
    b = main.Board()
    b.add_piece('r', 'a1', is_white=True)
    b.add_piece('p', 'a8', is_white=False)
    moves = b.get_naive_moves(from_white=True)
    moves_san = [m.to_string() for m in moves]
    takes = [m for m in moves if m.is_take]
    assert len(moves) == 14
    assert len(takes) == 1
    assert 'Ra4' in moves_san
    assert 'Rxa8' in moves_san
def test_pawn_takes_pawn():
    b = main.Board()
    b.add_piece('p', 'd4', is_white=True)
    b.add_piece('p', 'e5', is_white=False)
    moves = b.get_naive_moves(from_white=True)
    takes = [m for m in moves if m.is_take]
    assert len(moves) == 2
    assert len(takes) == 1
    moves_san = [m.to_string() for m in moves]
    assert 'd5' in moves_san
    assert 'dxe5' in moves_san
Пример #23
0
def test_add_piece():
    b = main.Board()
    b.add_piece('p', 'b2', False)
    should_be = ['........']
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('.p......')
    should_be.append('........')
    assert should_be == b.get_board()
Пример #24
0
def test_cant_castle_rook_moved():
    b = main.Board()
    b.init_default()
    b.process_move('h4')
    b.process_move('h5')
    b.process_move('Rh2')
    assert not b.white_can_castle_k
    b.process_move('e6')
    b.process_move('a4')
    b.process_move('e5')
    b.process_move('Ra2')
    assert not b.white_can_castle_q
Пример #25
0
def test_simple():
    b = main.Board()
    b.init_simple()
    should_be = ['........']
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('.P......')
    assert should_be == b.get_board()
Пример #26
0
def test_default():
    b = main.Board()
    b.init_default()
    should_be = ['rnbqkbnr']
    should_be.append('pppppppp')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('........')
    should_be.append('PPPPPPPP')
    should_be.append('RNBQKBNR')
    assert should_be == b.get_board()
def test_lonely_centered_knight_white():
    b = main.Board()
    b.add_piece('n', 'd4', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 8
    assert 'Ne6' in moves
    assert 'Nf5' in moves
    assert 'Nc6' in moves
    assert 'Nb5' in moves
    assert 'Ne2' in moves
    assert 'Nf3' in moves
    assert 'Nc2' in moves
    assert 'Nb3' in moves
def test_lonely_centered_king_white():
    b = main.Board()
    b.add_piece('k', 'd4', True)
    moves = [m.to_string() for m in b.get_naive_moves(from_white=True)]
    assert len(moves) == 8
    assert 'Kd5' in moves
    assert 'Kd3' in moves
    assert 'Ke5' in moves
    assert 'Ke3' in moves
    assert 'Kc5' in moves
    assert 'Kc3' in moves
    assert 'Kc4' in moves
    assert 'Ke4' in moves
Пример #29
0
def test_reverse_few_moves():
    b = main.Board()
    b.init_default()
    b.process_move('d4')
    b.process_move('e5')
    b.process_move('dxe5')
    b.process_move('Nf6')
    b.process_move('f3')
    b.process_move('Bb4')
    b.process_move('Qd2')
    b.process_move('O-O')
    fen = "rnbq1rk1/pppp1ppp/5n2/4P3/1b6/5P2/PPPQP1PP/RNB1KBNR w KQ - 0 1"
    assert b.to_fen() == fen
def test_knight_takes_pawns():
    b = main.Board()
    b.add_piece('n', 'd4', is_white=True)
    b.add_piece('p', 'e6', is_white=False)
    b.add_piece('p', 'c2', is_white=False)
    moves = b.get_naive_moves(from_white=True)
    moves_san = [m.to_string() for m in moves]
    takes = [m for m in moves if m.is_take]
    assert len(moves) == 8
    assert len(takes) == 2
    assert 'Nf5' in moves_san
    assert 'Nxe6' in moves_san
    assert 'Nxc2' in moves_san