Created
August 10, 2017 22:01
-
-
Save zorix/07372c43cd56da254e9e07ebb1dbfba4 to your computer and use it in GitHub Desktop.
Solver for mission 14 - https://www.youtube.com/watch?v=rhsH-snYkIc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
W = 57 | |
H = 25 | |
MAP = bytearray(" "*W*H) | |
counter = 0 | |
class Walker(object): | |
def __init__(self): | |
self.x = 0 # Starting pos. | |
self.y = 9 | |
def walk(self, lines): | |
directions = [ | |
( "EAST", 1, 0 ), | |
( "NORTH", 0, -1 ), | |
( "WEST", -1, 0 ), | |
( "SOUTH", 0, 1 ) | |
] | |
for d in directions: | |
if not lines: | |
return | |
l = lines.pop(0) | |
assert(l == ("Trying... " + d[0])) | |
nx = self.x + d[1] | |
ny = self.y + d[2] | |
l = lines.pop(0) | |
if l == "Already visited!": | |
continue | |
elif l == "There be dragons!": | |
continue | |
elif l == "A wild wall appears!": | |
MAP[ny * W + nx] = chr(255) | |
continue | |
elif l == "Taking a step.": | |
MAP[ny * W + nx] = chr(0) | |
self.x += d[1] | |
self.y += d[2] | |
self.walk(lines) | |
l = lines.pop(0) | |
assert(l == "Steping back.") | |
self.x -= d[1] | |
self.y -= d[2] | |
else: | |
assert False | |
#if (nx, ny) in self.visited: | |
# log.append("Already visited!") | |
# continue | |
#result = self.is_floor(nx, ny) | |
#if result is not True: | |
# log.append(result) | |
# continue | |
#log.append("Taking a step.") | |
#self.visited.add((self.x, self.y)) | |
#self.walk(lines) | |
#log.append("Steping back.") | |
lines = open("log.txt", "rb").read().splitlines() | |
w = Walker() | |
w.walk(lines) | |
from PIL import Image | |
img = Image.frombytes('L', (W, H), str(MAP)) | |
img.save('picture.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment