示例#1
0
def run_with_screen(program):
    computer = Computer(program)
    pad = 0
    ball = 0
    done = False
    score = 0

    while not done:
        computer.next_input = lambda: joystick(pad, ball)

        computer.iterate()
        x = computer.output

        computer.iterate()
        y = computer.output

        done = computer.iterate()
        tile = computer.output

        if tile == 4:
            ball = x
        if tile == 3:
            pad = x

        if x == -1 and y == 0:
            score = tile

        if done:
            return score
示例#2
0
文件: 21.py 项目: pjot/advent-of-code
def run_sprintscript(spring):
    program = parse_file('game.intcode')
    c = Computer(program)
    i = inputter([ord(c) for c in spring])
    c.next_input = i.next
    o = c.run_to_output()
    for ch in o:
        if ch < 128:
            print(chr(ch), end='')
        else:
            print(ch)
    print()
    print()
示例#3
0
文件: 17.py 项目: pjot/advent-of-code
p = ','.join(str(s) for s in path)
print('Path:', p)

program = parse_file("input.intcode")
program[0] = 2
computer = Computer(program)

with open('robot_path.txt') as f:
    inputs = []
    for line in f.readlines():
        for c in line:
            inputs.append(ord(c))


class inputter:
    def __init__(self, inputs):
        self.inputs = inputs

    def next(self):
        n = self.inputs.pop(0)
        return n


inp = inputter(inputs)
computer.next_input = inp.next
done = False
while not done:
    done = computer.iterate()

print("Part 2:", computer.output)
示例#4
0
def check(x, y):
    inputs = inputter([x, y])
    computer = Computer(parse_file('input.intcode'))
    computer.next_input = inputs.next
    computer.iterate()
    return computer.output == 1