Skip to content

Instantly share code, notes, and snippets.

@5nyper
Created June 10, 2017 05:59
Show Gist options
  • Save 5nyper/7d647e1c2df288143365cabaee624252 to your computer and use it in GitHub Desktop.
Save 5nyper/7d647e1c2df288143365cabaee624252 to your computer and use it in GitHub Desktop.
Python
from socket import create_connection
MAZE_SERVER = ('54.69.145.229', 16000)
RECV_SIZE = 8192
def main():
conn = create_connection(MAZE_SERVER)
response = conn.recv(RECV_SIZE)
while True:
print response
if "Now " not in response:
return
response_lines = response.splitlines()
find_delim = [x for x in response_lines if x.startswith('Now')][0]
maze_lines = response_lines[response_lines.index(find_delim)+2:-1]
maze_text = '\n'.join(maze_lines)
moves = []
past_paths = []
current_pos = []
starting_pos = []
X_pos = []
found_X = False
past_move = ""
for i, line in enumerate(maze_lines):
for k, pos in enumerate(line):
if pos == '>':
current_pos = [i,k]
starting_pos = [i,k]
if pos == "X":
X_pos = [i,k]
print maze_lines[current_pos[0]][current_pos[1]+1]
while(not found_X):
if(maze_lines[current_pos[0]][current_pos[1]+1] != "#" and past_move != "<"): # right
current_pos = [current_pos[0],current_pos[1]+1]
past_move = ">"
moves.append(">")
elif(maze_lines[current_pos[0]][current_pos[1]-1] != "#" and past_move != ">"): # left
current_pos = [current_pos[0],current_pos[1]-1]
past_move = "<"
moves.append("<")
elif(maze_lines[current_pos[0]+1][current_pos[1]] != "#" and past_move != "V"): # up
current_pos = [current_pos[0]+1, current_pos[1]]
past_move = "^"
moves.append("^")
elif(maze_lines[current_pos[0]-1][current_pos[1]] != "#" and past_move != "^"): # down
current_pos = [current_pos[0]-1, current_pos[1]+1]
past_move = "V"
moves.append("V")
elif(current_pos == X_pos):
found_X = True
else:
current_pos = starting_pos
past_paths = moves
print past_paths
moves = []
#print moves
solution = raw_input("Your solution: ")
if not len(solution):
return
conn.send(solution)
response = conn.recv(RECV_SIZE)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment