Ejemplo n.º 1
0
def run_robot_run(core):

    panel = {}
    pr = PaintingRobot()

    computer = IntCodeComputer()
    computer.load_core(core)
    computer.state = ProgramState.running
    while computer.state == ProgramState.running:
        computer.set_input_buffer([pr.camera(panel)])

        inst = [None, None]
        while len(computer.output_buffer) == 0:
            computer.step()
            if computer.state != ProgramState.running:
                return len(pr._painted_panels)

        inst[0] = computer.output_buffer.pop()

        while len(computer.output_buffer) == 0:
            computer.step()
        inst[1] = computer.output_buffer.pop()

        pr.paint(inst[0], panel)
        pr.turn(inst[1])
Ejemplo n.º 2
0
def main():
    with open("015.1.input.txt", "r") as f:
        core = [int(c) for c in f.readline().strip().split(",")]

    visited = {(0, 0): 3}
    computer = IntCodeComputer()
    computer.load_core(core)
    computer.state = ProgramState.running
    search_q = deque([Droid(computer, loc=(0, 0), depth=0)])

    while search_q:
        droid = search_q.popleft()
        for move in all_moves:
            res, new_droid = droid.clone_and_move(move)
            if res == 0:
                visited[new_droid.loc] = 1
                continue
            elif res == 1:
                if new_droid.loc in visited:
                    continue
                else:
                    search_q.append(new_droid)
                    visited[new_droid.loc] = 2
            elif res == 2:
                visited[new_droid.loc] = 4
                print(new_droid.depth)
                return 0

        display_visited(visited)
        print(droid.depth)
        time.sleep(.1)
Ejemplo n.º 3
0
def main():
    with open(sys.argv[1], "r") as f:
        core = [int(c) for c in f.readline().strip().split(",")]

    screen = {}

    computer = IntCodeComputer()
    computer.load_core(core)
    computer.state = ProgramState.running
    while computer.state == ProgramState.running:
        computer.step()

        if len(computer.output_buffer) == 3:
            x, y, t = computer.output_buffer
            computer.output_buffer.clear()
            screen[(x, y)] = t

    print(len([s for s in screen.values() if s == 2]))
    print_screen(screen)
Ejemplo n.º 4
0
def create_map():
    with open("015.1.input.txt", "r") as f:
        core = [int(c) for c in f.readline().strip().split(",")]

    # 1 = block
    # 2 = corridor

    visited = {(0, 0): 2}
    computer = IntCodeComputer()
    computer.load_core(core)
    computer.state = ProgramState.running
    search_q = deque([Droid(computer, loc=(0, 0), depth=0)])

    oxy_source = None

    while search_q:
        droid = search_q.popleft()
        for move in all_moves:
            loc2 = new_loc(droid.loc, move)
            if loc2 in visited:
                continue

            res, new_droid = droid.clone_and_move(move)
            if res == 0:
                visited[new_droid.loc] = 1
                continue
            else:
                search_q.append(new_droid)
                visited[new_droid.loc] = 2
                if res == 2:
                    oxy_source = new_droid.loc

        display_visited(visited)
        print(f"Mapping: depth={droid.depth} clones={len(search_q)}")
        time.sleep(.01)

    return visited, oxy_source
Ejemplo n.º 5
0
south
take dark matter
north
east
north
west
south
take antenna
north
east
south
east
take bowl of rice
north
take klein bottle
north
take spool of cat6
west
"""

ascii_cmds = [ord(char) for char in cmds]
_, prints, status = computer.run(input_values=ascii_cmds)

while True:
    cmd = input()
    ascii_cmd = [ord(char) for char in cmd + '\n']
    _, prints, status = computer.run(input_values=ascii_cmd)
    for line in prints2ascii(prints):
        print(line)
    computer.state = computer.state[:-1] + ([], )