Skip to content

Instantly share code, notes, and snippets.

@pawlos
Created August 14, 2017 06:26
Show Gist options
  • Select an option

  • Save pawlos/5159a4a856ef0b3925c16079074ee0a2 to your computer and use it in GitHub Desktop.

Select an option

Save pawlos/5159a4a856ef0b3925c16079074ee0a2 to your computer and use it in GitHub Desktop.
Solution script for Mission 14
class Stack:
def __init__(self):
self.__storage = []
def isEmpty(self):
return len(self.__storage) == 0
def push(self,p):
self.__storage.append(p)
def pop(self):
return self.__storage.pop()
def p(self):
print self.__storage
W = 57
H = 25
dx = 0
dy = 0
cur_pos = {'x':0,'y':9, 'action': 'Init'}
stack = Stack()
stack.push(cur_pos)
with open('log.txt') as f, open('map.raw','wb') as d:
d.write("#"*W*H)
pos = (max(cur_pos['y']+dy,0))*W +(max(cur_pos['x']+dx,0))
d.seek(pos)
d.write('.')
for l in f:
print l
if "break" in l:
break
if "EAST" in l:
dx = 1
dy = 0
act = "EAST"
if "WEST" in l:
dx = -1
dy = 0
act = "WEST"
if "NORTH" in l:
dx = 0
dy = -1
act = "NORTH"
if "SOUTH" in l:
dx = 0
dy = 1
act = "SOUTH"
if "Steping back." in l:
cur_pos = stack.pop()
print 'A step back to: x: '+str(cur_pos['x'])+', y: '+str(cur_pos['y'])
if "Taking a step." in l:
pos = (max(cur_pos['y']+dy,0))*W +(max(cur_pos['x']+dx,0))
d.seek(pos)
d.write('.')
stack.push({'x':cur_pos['x'],'y':cur_pos['y']})
cur_pos = {'x':cur_pos['x']+dx,'y':cur_pos['y'] +dy, 'action': act}
print cur_pos
pos = (max(cur_pos['y'],0))*W +(max(cur_pos['x'],0))
d.seek(pos)
d.write('.')
if "There be dragons!" in l:
continue
if "A wild wall appears!" in l:
pos = {'x':max(cur_pos['x']+dx,0),'y':max(cur_pos['y']+dy,0)}
print "Wall at: ",pos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment