4 from itertools import chain
5 import pickle, readchar
10 conn = remote(host, port)
17 def print_map(printpos=None):
20 while len(temp) <= printpos[1]:
22 while len(temp[printpos[1]]) <= printpos[0]:
23 temp[printpos[1]].append('?')
24 temp[printpos[1]][printpos[0]] = str(temp[printpos[1]][printpos[0]])+'O'
26 .replace('], ', ']\n ')
27 .replace("breeze", "B")
28 #.replace("smell", "i")
29 .replace("'?'", "' '")
37 with open("servermap", 'rb') as f:
38 servermap = pickle.load(f)
42 while len(servermap) <= pos[1]:
43 servermap.append(['?'])
44 while len(servermap[pos[1]]) <= pos[0]:
45 servermap[pos[1]].append('?')
46 # print(f'setting {pos} {pos[1]} {pos[0]} to {val}')
47 servermap[pos[1]][pos[0]] = val
50 def get_current_position():
51 if not conn.connected():
53 line = (conn.recvuntil('\n', True).decode())
54 x = line.split('\x00')
61 def get_map_val(position=pos):
63 return servermap[position[1]][position[0]]
68 x = get_current_position()
72 print('sendline error')
80 if res not in ('iw', 'd'):
90 if res not in ('iw', 'd'):
99 if res not in ('iw', 'd'):
108 if res not in ('iw', 'd'):
141 c = readchar.readchar()
160 #if get_map_val((x, y+1)) in ('iw', 'B'): # B below
163 #if get_map_val((x, y-1)) in ('iw', 'B'): # B above
166 #if get_map_val((x+1, y)) in ('iw', 'B'): # B right
169 #if get_map_val((x-1, y)) in ('iw', 'B'): # B left
172 #print('no B in sight - go right')
175 with open("servermap", "wb") as f:
176 pickle.dump(servermap, f)
181 with open("flagchars.txt", "a") as myfile:
182 myfile.write(repr(flag_chars)+'\r\n')