def cameraOutput(defaultColor=0): code = getInputData() IC = IntcodeComputer(code) step = 0 inp = [] IC._output = [] # Clear the output list terminate = False stoppedAtInput = False while not terminate: while not stoppedAtInput and not terminate: terminate, stoppedAtInput = IC.perform_one_operation( IC._memoryPosition, inp, stopAtInput=True) step += 1 # print(f'### STEP {step} ###') # print(f'OutPut{IC._output}') # print(f'OutPut{IC._output}') stoppedAtInput = False ret = decodeMap(IC._output) # ret = [] # row = '' # for ascii in IC._output: # if str(ascii) == '10': # ret.append(row) # row = '' # else: # row += chr(ascii) return ret
def startRobot(defaultColor=0): code = getInputData() IC = IntcodeComputer(code) robotOnMap = SolarPanelMap(defaultColor=defaultColor) step = 0 inp = [defaultColor] IC._output = [] # Clear the output list terminate = False stoppedAtInput = False while not terminate: while not stoppedAtInput and not terminate: terminate, stoppedAtInput = IC.perform_one_operation( IC._memoryPosition, inp, stopAtInput=True) step += 1 # print(f'### STEP {step} ###') # print(f'OutPut{IC._output}') paintBlack = (IC._output.pop(0) == 0) # print(f'OutPut{IC._output}') turnLeft = (IC._output.pop(0) == 0) # print(f'OutPut{IC._output}') if paintBlack: robotOnMap.paintBlack() else: robotOnMap.paintWhite() if turnLeft: robotOnMap.turnLeft() else: robotOnMap.turnRight() robotOnMap.moveForward() color = robotOnMap.getColor() # 0=black, 1=white inp = [color] stoppedAtInput = False val = robotOnMap.countPaintedPanels() return val, robotOnMap._panelMap
def runGame(display): code = getInputData() IC = IntcodeComputer(code) # game = PILScreen() if display: game = Blocker(841, 600) count = 0 paddlePos = 0 # Set memory position 0 to 2, to play for free # IC.writeMem(0,2) ################## step = 0 inp = [] #input?? IC._output = [] # Clear the output list terminate = False stoppedAtInput = False HiScore = 0 while not terminate: length = 0 while length < 3 and not terminate: terminate, stoppedAtInput = IC.perform_one_operation( input=inp, stopAtInput=True) length = len(IC._output) # print(f'OutPut: {IC._output}') # print(f'Terminate: {terminate}') # print(f'stoppedAtInput: {stoppedAtInput}') # print(f'count: {count}') # print(f'Next instr: {IC._intCodeProgramDict[IC._memoryPosition]}') # print(f'Next memPos:{IC._memoryPosition}') if terminate: break try: x = IC._output[0] y = IC._output[1] t = IC._output[2] IC._output = [] except Exception: print('EXCEPTION') break #game.show() ######## TILES # # 0 is an empty tile. No game object appears in this tile. # 1 is a wall tile. Walls are indestructible barriers. # 2 is a block tile. Blocks can be broken by the ball. # 3 is a horizontal paddle tile. The paddle is indestructible. # 4 is a ball tile. The ball moves diagonally and bounces off objects. if t == 3: paddlePos = x if t == 4: if paddlePos < x: inp = [1] elif paddlePos > x: inp = [-1] else: inp = [0] if x == -1 and y == 0: # -1, 0, t gives SCORE if t > HiScore: HiScore = t if display: game.draw_text(str(HiScore)) else: if t == 2: count += 1 #if t != 0: if display: game.drawBrick(x, y, t) if display: game.screen_update() return count, HiScore