def make_maze_grid(filename): tunnels = [] f = open(filename) for line in f.readlines(): tunnels.append([c for c in line.strip()]) f.close() maze_grid = grid.Grid(len(tunnels), len(tunnels[0])) # This is already a maze_grid, no need to set anything right now. for y in range(maze_grid.rows): for x in range(maze_grid.columns): maze_grid.set(grid.Point(x, y), tunnels[y][x]) maze_grid.render() return maze_grid
def RunRound2(lines, last_g): # initialize new grid new_g = grid.Grid(lines) for y in range(last_g.rows): for x in range(last_g.columns): location = grid.Point(x, y) value = last_g.get(location) if value == OCCUPIED and last_g.count_visible_seats( location, OCCUPIED) >= 5: new_g.set(location, EMPTY) elif value == EMPTY and last_g.count_visible_seats( location, OCCUPIED) == 0: new_g.set(location, OCCUPIED) else: new_g.set(location, value) #new_g.render() return new_g
def build_graph(maze_grid): graph1 = graph.Graph() # Add all nodes. for y in range(maze_grid.rows): for x in range(maze_grid.columns): location = grid.Point(x, y) c = maze_grid.get(location) if c != '#' and c != '.': graph1.add_node(location, maze_grid.get(location)) for current in graph1.nodes.values(): nodes = bfs_maze_grid(maze_grid, current) for n in nodes: # Avoid self-edges. if n != current.value: node = graph1.nodes[current.value] node.add_edge(graph1.nodes[n], nodes[n]) graph1.build_dependency_graph() return graph1
def capture_data_fragment(points): centre = grid.Point(points_list=points) distance = centre.distance(points[0]) json_data = send_request_one_square(centre=centre, distance=distance) save_to_file(globs.general.PROPER_DATA_FILE_API, globs.general.LOG_FILE_PATH_API, json_data, centre, distance)