Beispiel #1
0
def run_bot(screen):
    f = open('input.txt').read()
    vm = IntcodeVm(f)

    ds = '^>v<'
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    max_x, max_y = 50, 12
    i, j, d = 0, max_y // 2, 0
    grid = [[0 for x in range(max_x)] for y in range(max_y)]

    grid[j][i] = 1

    def grid_in():
        while True:
            yield grid[j][i]

    g_in = grid_in()

    while True:
        p = vm.eval(g_in)
        if p is None: break
        grid[j][i] = p
        p = vm.eval(g_in)
        if p is None: break
        if p == 0: p = -1
        d = (d + p) % 4
        i += dx[d]
        j += dy[d]

        v = grid[j][i]
        grid[j][i] = 2
        draw(screen, grid, (i, j), ds[d])
        grid[j][i] = v
    time.sleep(10)
Beispiel #2
0
def run_game(screen, data):
    mem = parse_memory(data)
    mem[0] = 2
    vm = IntcodeVm(mem)

    grid = [[tiles[0] for _ in range(48)] for _ in range(24)]
    score = 0
    ai = agent(grid)

    i = 0
    while True:
        i += 1
        x = vm.eval(ai)
        if x is None: break
        y = vm.eval(ai)
        t = vm.eval(ai)
        if x == -1 and y == 0: score = t
        else: grid[y][x] = tiles[t]
        if i % 1 == 0:
            draw(screen, grid, score)
            time.sleep(0.005)
    draw(screen, grid, score)
    time.sleep(10)