Exemplo n.º 1
0
def test_fen_existing_state():
    b = ab.AsciiBoard()
    b.reset()
    b.apply(
        m.Move(source='b1',
               target='a3',
               target2='c3',
               move_type=MoveType.SPLIT_JUMP,
               move_variant=MoveVariant.BASIC))
    b.reset()

    expected_board = ab.AsciiBoard()
    expected_board.reset()
    assert str(b) == str(expected_board)
Exemplo n.º 2
0
def main_loop(args):
    f = open(args.filename, 'r')
    moves = [line.strip() for line in f]
    board = create_board(processor_name=args.processor_name,
                         noise_mitigation=0.1)
    b = ab.AsciiBoard(board=board)
    if args.position:
        b.load_fen(args.position)
    else:
        b.reset()
    print(f'Applying moves to board...')
    apply_moves(b, moves)
    print(b)
Exemplo n.º 3
0
def test_fen():
    b = ab.AsciiBoard()
    b.load_fen('8/8/8/8/2pB2p1/1kP3P1/P3P3/2bb4')
    expected_pieces = {
        'c4': -c.PAWN,
        'd4': c.BISHOP,
        'g4': -c.PAWN,
        'b3': -c.KING,
        'c3': c.PAWN,
        'g3': c.PAWN,
        'a2': c.PAWN,
        'e2': c.PAWN,
        'c1': -c.BISHOP,
        'd1': -c.BISHOP,
    }
    for x in range(8):
        for y in range(8):
            square = m.to_square(x, y)
            assert b._pieces[square] == expected_pieces.get(square, c.EMPTY)
Exemplo n.º 4
0
def test_fen():
    b = ab.AsciiBoard()
    b.load_fen("8/8/8/8/2pB2p1/1kP3P1/P3P3/2bb4")
    expected_pieces = {
        "c4": -c.PAWN,
        "d4": c.BISHOP,
        "g4": -c.PAWN,
        "b3": -c.KING,
        "c3": c.PAWN,
        "g3": c.PAWN,
        "a2": c.PAWN,
        "e2": c.PAWN,
        "c1": -c.BISHOP,
        "d1": -c.BISHOP,
    }
    for x in range(8):
        for y in range(8):
            square = m.to_square(x, y)
            assert b._pieces[square] == expected_pieces.get(square, c.EMPTY)
Exemplo n.º 5
0
def main_loop(args):
    b = ab.AsciiBoard()
    if args.position:
        b.load_fen(args.position)
    else:
        b.reset()
    print(b)
    for in_str in sys.stdin:
        in_str = in_str.strip()
        if in_str == 'exit':
            return
        if not in_str:
            continue
        if ':' not in in_str:
            in_str = in_str + ':JUMP:BASIC'
        in_move = m.Move.from_string(in_str)
        meas = b.apply(in_move)
        b.board.print_debug_log()
        print(f'Measurement outcome = {meas}')
        print('')
        print(b)
        print('')
Exemplo n.º 6
0
def main_loop(args):
    f = open(args.filename, 'r')
    moves = [line.strip() for line in f]
    if args.processor_name:
        processor_name = args.processor_name
    else:
        # Execute on a quantum processor if it is available.
        available_processors = utils.get_available_processors(
            utils.QUANTUM_PROCESSORS.keys())
        if available_processors:
            processor_name = available_processors[0]
        else:
            processor_name = 'Syc54-noiseless'
    print(f'Using processor {processor_name}')
    board = create_board(processor_name=processor_name, noise_mitigation=0.1)
    b = ab.AsciiBoard(board=board)
    if args.position:
        b.load_fen(args.position)
    else:
        b.reset()
    print(f'Applying moves to board...')
    apply_moves(b, moves)
    print(b)
Exemplo n.º 7
0
def main_loop(args):
    b = ab.AsciiBoard()
    if args.position:
        b.load_fen(args.position)
    else:
        b.reset()
    print(b)
    b.board.clear_debug_log()
    for in_str in sys.stdin:
        in_str = in_str.strip()
        if in_str == "exit":
            return
        if not in_str:
            continue
        if ":" not in in_str:
            in_str = in_str + ":JUMP:BASIC"
        in_move = m.Move.from_string(in_str)
        meas = b.apply(in_move)
        print(b.board.circuit)
        b.board.print_debug_log()
        print(f"Measurement outcome = {meas}")
        print("")
        print(b)
        print("")
Exemplo n.º 8
0
def test_ep_flag():
    b = ab.AsciiBoard()
    b.reset()
    assert b._ep_flag(m.Move('b2', 'b3'), c.PAWN) == None
    assert b._ep_flag(m.Move('b2', 'b4'), c.KNIGHT) == None
    assert b._ep_flag(m.Move('b2', 'b4'), c.PAWN) == 1
Exemplo n.º 9
0
def test_ep_flag():
    b = ab.AsciiBoard()
    b.reset()
    assert b._ep_flag(m.Move("b2", "b3"), c.PAWN) is None
    assert b._ep_flag(m.Move("b2", "b4"), c.KNIGHT) is None
    assert b._ep_flag(m.Move("b2", "b4"), c.PAWN) == 1