Exemple #1
0
    def run(self):
        from chess import Board

        b = Board("8/8/8/8/4K3/8/8/8 b KQkq - 0 1")

        assert b.attacked_fields(0) == 0
        assert b.attacked_fields(1) == (int('00011100', 2) << 32) | int('00010100', 2) << 24 | int('00011100', 2) << 16

        b.from_fen("8/8/8/8/8/8/8/7k b KQkq - 0 1")
        assert b.attacked_fields(1) == 0
        assert b.attacked_fields(0) == (int('00000010', 2)) | int('00000011', 2) << 8
Exemple #2
0
    def run(self):
        from chess import Board, RANK_7, RANK_2

        # new game is loaded when no fence is passed
        b = Board()
        assert (b.active_player == 1)
        assert b.black_king_side_castle_right
        assert b.black_queen_side_castle_right
        assert b.white_king_side_castle_right
        assert b.white_queen_side_castle_right
        assert b.move_number == 1
        assert b.half_move_clock == 0
        assert b._all_black_pieces() == int('1111111111111111', 2) << 48
        assert b._all_white_pieces() == int('1111111111111111', 2)
        assert b.PIECES['p'] == RANK_7
        assert b.PIECES['P'] == RANK_2
        assert b.PIECES['k'] == int('00001000', 2) << 56
        assert b.PIECES['K'] == int('00001000', 2)
        assert b.PIECES['q'] == int('00010000', 2) << 56
        assert b.PIECES['Q'] == int('00010000', 2)
        assert b.PIECES['n'] == int('01000010', 2) << 56
        assert b.PIECES['N'] == int('01000010', 2)
        assert b.PIECES['b'] == int('00100100', 2) << 56
        assert b.PIECES['B'] == int('00100100', 2)
        assert b.PIECES['r'] == int('10000001', 2) << 56
        assert b.PIECES['R'] == int('10000001', 2)

        # whites moves pawn two steps
        b.from_fen("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1")
        assert b.ep_move == "e3"
        assert b.active_player == 0
        assert b.PIECES['P'] == int('00001000', 2) << 24 | int('11110111', 2) << 8

        # black also moves a pawn two steps
        b.from_fen("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2")
        assert b.ep_move == "c6"
        assert b.move_number == 2
        assert b.active_player == 1
        assert b.PIECES['P'] == int('00001000', 2) << 24 | int('11110111', 2) << 8
        assert b.PIECES['p'] == int('00100000', 2) << 32 | int('11011111', 2) << 48

        # whites moves its knight
        b.from_fen("rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2")
        assert b.ep_move is None
        assert b.active_player == 0
        assert b.black_king_side_castle_right
        assert b.black_queen_side_castle_right
        assert b.white_king_side_castle_right
        assert b.white_queen_side_castle_right
        assert b.PIECES['P'] == int('00001000', 2) << 24 | int('11110111', 2) << 8
        assert b.PIECES['p'] == int('00100000', 2) << 32 | int('11011111', 2) << 48
        assert b.PIECES['N'] == int('01000000', 2) | int('00000100', 2) << 16

        # to fen
        test_fen = "rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2"
        b.from_fen(test_fen)
        assert b.to_fen() == test_fen