Ejemplo n.º 1
0
def main(stdscr):
    curses.curs_set(0)
    with open(sys.argv[1]) as f:
        line = f.readline()

    # set mem address 0 to 2 so we can play for free
    opcode = OpcodeComputer.Opcode(line, "game", {0 : 2})

    coord = []

    score = 0

    while True:
        bally = False
        paddley = False
        if len(coord) == 3:
            if coord[0] == -1 and coord[1] == 0:
                score = coord[2]
                stdscr.addstr(0, 13, "Score: " + str(score))
            else:
                game[(coord[1], coord[0])] = coord[2]

                tile = ""
                if coord[2] == 0:
                    tile = " "
                elif coord[2] == 1:
                    tile = u"\u2588"
                elif coord[2] == 2:
                    tile = "#"
                elif coord[2] == 3:
                    tile = u"\u1397"
                elif coord[2] == 4:
                    tile = "O"
                stdscr.addstr(coord[1] + 1, coord[0], tile)
                stdscr.refresh()
            coord = []
            # uncomment next 2 lines to show game
            # printgame(game, score)
            # print("\n")
            bally = getbally(game)
            paddley = getpaddley(game)

        if bally and paddley:
            time.sleep(0.005)
            if paddley == bally:
                coord.append(opcode.runOpcode(0))
            elif paddley > bally:
                coord.append(opcode.runOpcode(-1))
            elif paddley < bally:
                coord.append(opcode.runOpcode(1))
        else:
            coord.append(opcode.runOpcode())

        if opcode.checkifdone():
            break

    print(score)
Ejemplo n.º 2
0
import sys
import OpcodeComputer

with open(sys.argv[1]) as f:
    line = f.readline()
    opcode = OpcodeComputer.Opcode(line)

    diagnosticcode = 0
    while diagnosticcode == 0:
        diagnosticcode = opcode.runOpcode(1)
    print(diagnosticcode)
Ejemplo n.º 3
0
import sys
import os
import OpcodeComputer
import time

intcode = None

with open(sys.argv[1]) as f:
    line = f.readline()
    intcode = OpcodeComputer.Opcode(line, "map", {0: 2})

def getascii(s):
    retarr = []
    commands = s.split(",")
    for i in commands:
        if len(retarr):
            retarr.append(44)
        for c in i:
            retarr.append(ord(c))
    retarr.append(10)
    return retarr
        

mmr = getascii("A,B,A,B,A,C,B,C,A,C")
A = getascii("R,4,L,10,L,10")
B = getascii("L,8,R,12,R,10,R,4")
C = getascii("L,8,L,8,R,10,R,4")

# [65, 44, 66, 44, 65, 44, 66, 44, 65, 44, 67, 44, 66, 44, 67, 44, 65, 44, 67, 10]
# [82, 44, 52, 44, 76, 44, 49, 48, 44, 76, 44, 49, 48, 10]
# [76, 44, 56, 44, 82, 44, 49, 50, 44, 82, 44, 49, 48, 44, 82, 44, 52, 10]
Ejemplo n.º 4
0
import sys
import os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import OpcodeComputer

with open(sys.argv[1]) as f:
    line = f.readline()

    sleighsize = 100
    sleighoffset = sleighsize - 1

    x = 929
    y = 911

    print(OpcodeComputer.Opcode(line).runOpcode([x, y]))
    print(OpcodeComputer.Opcode(line).runOpcode([x + sleighoffset, y]))    
    print(OpcodeComputer.Opcode(line).runOpcode([x + sleighoffset, y - (sleighoffset)]))
Ejemplo n.º 5
0
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import OpcodeComputer

with open(sys.argv[1]) as f:
    line = f.readline()

    sleighsize = 100
    sleighoffset = sleighsize - 1

    count = 0

    lowestx = 0

    # opcode = OpcodeComputer.Opcode(line)
    y = 10  # start at 10 to skip those first few lines that don't get hit by beam
    while True:
        x = lowestx
        while True:
            if OpcodeComputer.Opcode(line).runOpcode([x, y]):
                # print("F", x, y)
                lowestx = x
                # if OpcodeComputer.Opcode(line).runOpcode([x + sleighoffset, y]):
                if y - (sleighsize - 1) >= 0:
                    if OpcodeComputer.Opcode(line).runOpcode(
                        [x + sleighoffset, y - sleighoffset]):
                        print(x * 10000 + (y - sleighoffset))
                        exit()
                break
            x += 1
        y += 1
Ejemplo n.º 6
0
with open(sys.argv[1]) as f:
    line = f.readline()

natx = None
naty = None
lasty = None

def idle(n):
    for i in n:
        if i.input:
            return False
    return True

nics = []
for i in range(0, 50):
    nics.append(OpcodeComputer.Opcode(line, i))

for i in range(0, 50):
    addr = nics[i].runOpcode([i])

while True:
    for i in range(0, 50):
        if nics[i].input:
            while nics[i].input:
                nics[i].runOpcode()
        else:
            nics[i].runOpcode(-1)
        while len(nics[i].packet) >= 3:
            addr = nics[i].packet.pop(0)
            x = nics[i].packet.pop(0)
            y = nics[i].packet.pop(0)
Ejemplo n.º 7
0
            return k[1]
    return False


def getpaddley(game):
    for k, v in game.items():
        if v == 3:
            return k[1]
    return False


with open(sys.argv[1]) as f:
    line = f.readline()

# set mem address 0 to 2 so we can play for free
opcode = OpcodeComputer.Opcode(line, "game", {0: 2})

coord = []

score = 0

while True:
    bally = False
    paddley = False
    if len(coord) == 3:
        if coord[0] == -1 and coord[1] == 0:
            score = coord[2]
        game[(coord[1], coord[0])] = coord[2]
        coord = []
        # uncomment next 2 lines to show game
        printgame(game, score)
Ejemplo n.º 8
0
import os.path
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import OpcodeComputer

line = ""
with open(sys.argv[1]) as f:
    line = f.readline()

phasesettings = [5, 6, 7, 8, 9]

largestsignal = None

for i in permutations(phasesettings):
    inpoot = 0
    A = OpcodeComputer.Opcode(line, "A")
    B = OpcodeComputer.Opcode(line, "B")
    C = OpcodeComputer.Opcode(line, "C")
    D = OpcodeComputer.Opcode(line, "D")
    E = OpcodeComputer.Opcode(line, "E")

    inpoot = E.runOpcode([
        i[0],
        D.runOpcode([
            i[1],
            C.runOpcode([i[2],
                         B.runOpcode([i[3], A.runOpcode([i[4], 0])])])
        ])
    ])

    while not A.done and not B.done and not C.done and not D.done and not E.done:
Ejemplo n.º 9
0
import sys
import os.path
sys.path.append(
    os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import OpcodeComputer

with open(sys.argv[1]) as f:
    line = f.readline()

    count = 0

    # opcode = OpcodeComputer.Opcode(line)
    for y in range(0, 50):
        for x in range(0, 50):
            if OpcodeComputer.Opcode(line).runOpcode([x, y]):
                print("#", end="")
                count += 1
            else:
                print(".", end="")
        print()
    print(count)