def findRoute(self, src, dst): path = self.dijkstras_shortest_path(src, dst) if path: show_level(self.level, path) else: print "No path available"
def test_route(filename, src_waypoint, dst_waypoint): """ Loads a level, searches for a path between the given waypoints, and displays the result. Args: filename: The name of the text file containing the level. src_waypoint: The character associated with the initial waypoint. dst_waypoint: The character associated with the destination waypoint. """ # Load and display the level. level = load_level(filename) show_level(level) # Retrieve the source and destination coordinates from the level. src = level['waypoints'][src_waypoint] # if ((dst_waypoint.isalnum())): # print("No destination!") # else: dst = level['waypoints'][dst_waypoint] # Search for and display the path from src to dst. path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) else: print("No path possible!")
def write_path(filename, src_waypoint, dst_waypoint, ofname): """ Loads a level, searches for a path between the given waypoints, and displays the result. Args: filename: The name of the text file containing the level. src_waypoint: The character associated with the initial waypoint. dst_waypoint: The character associated with the destination waypoint. """ # Load and display the level. level = load_level(filename) #print("finding path from ", src_waypoint, " to ", dst_waypoint, " of this graph:") #show_level(level) #print("writing output to file: ", ofname) # Retrieve the source and destination coordinates from the level. src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] #save stdout tempstdout = sys.stdout stdout = open(ofname, "w") # Search for and display the path from src to dst. path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) else: print("No path possible!") stdout = tempstdout
def cost_to_all_cells(filename, src_waypoint, output_filename): """ Loads a level, calculates the cost to all reachable cells from src_waypoint, then saves the result in a csv file with name output_filename. Args: filename: The name of the text file containing the level. src_waypoint: The character associated with the initial waypoint. output_filename: The filename for the output csv file. """ # Load and display the level. level = load_level(filename) show_level(level) # Retrieve the source coordinates from the level. src = level['waypoints'][src_waypoint] # Calculate the cost to all reachable cells from src and save to a csv file. costs_to_all_cells = dijkstras_shortest_path_to_all( src, level, navigation_edges) save_level_costs(level, costs_to_all_cells, output_filename)
def test_route(filename, src_waypoint, dst_waypoint): level = load_level(filename) src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] path = dfs(src, dst, level, get_steps) show_level(level, path)
def test_route(filename, src_waypoint, dst_waypoint): level = load_level(filename) show_level(level) src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) else: print("No path possible!")
def test_route(filename, src_waypoint, dst_waypoint): level = load_level(filename) src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] path = dijk(src, dst, level, get_steps) if len(path) is not 0: show_level(level, path) else: print("There is no path from " + src_waypoint + " to " + dst_waypoint + ".")
def test_route(filename, src_waypoint, dst_waypoint): level = load_level(filename) show_level(level) src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) else: print "No path possible!"
def test_route(filename, src_waypoint, dst_waypoint, keyFound): level = load_level(filename, keyFound) print("source = " + src_waypoint + ",", "destination = " + dst_waypoint + ",", "Key found =", keyFound, "\n") src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] path = dijkstra(src, dst, level, get_steps) if path: show_level(level, path) else: show_level(level, path) print("No path possible!!!")
def test_route(filename, src_waypoint, dst_waypoint): #Level gets stored level = load_level(filename) #Level gets drawn on screen show_level(level) #src and dst are set. src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] #Path is found. path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) else: print "No path possible!"
def cost_to_all_cells(filename, src_waypoint, output_filename): """ Loads a level, calculates the cost to all reachable cells from src_waypoint, then saves the result in a csv file with name output_filename. Args: filename: The name of the text file containing the level. src_waypoint: The character associated with the initial waypoint. output_filename: The filename for the output csv file. """ # Load and display the level. level = load_level(filename) show_level(level) # Retrieve the source coordinates from the level. src = level['waypoints'][src_waypoint] # Calculate the cost to all reachable cells from src and save to a csv file. costs_to_all_cells = dijkstras_shortest_path_to_all(src, level, navigation_edges) save_level_costs(level, costs_to_all_cells, output_filename)
def test_route(filename, src_waypoint, dst_waypoint, output_filename): """ Loads a level, searches for a path between the given waypoints, and displays the result. Args: filename: The name of the text file containing the level. src_waypoint: The character associated with the initial waypoint. dst_waypoint: The character associated with the destination waypoint. """ # Load and display the level. level = load_level(filename) show_level(level) # Retrieve the source and destination coordinates from the level. src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] # Search for and display the path from src to dst. #haphazardly edited to output to file aswell as stdout path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) original_out = sys.stdout f = open(output_filename, "w+") sys.stdout = f show_level(level, path) sys.stdout = original_out f.close print("Saved file:", output_filename) else: print("No path possible!")
def export_new_maze(filename, destinationfile, src_waypoint, dst_waypoint): level = load_level(filename) show_level(level) # Retrieve the source and destination coordinates from the level. src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] # Search for and display the path from src to dst. path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) with open(destinationfile, "w") as f: with redirect_stdout(f): show_level(level, path) print("Wrote to " + destinationfile) else: print("No path possible!")
def test_route(filename, src_waypoint, dst_waypoint): level = load_level(filename) if VERBOSE: print("Level layout:") show_level(level) src = level['waypoints'][src_waypoint] dst = level['waypoints'][dst_waypoint] path = dijkstras_shortest_path(src, dst, level, navigation_edges) if path: show_level(level, path) else: print "No path possible!" # Show the level if the user hasn't already seen it if not VERBOSE: show_level(level, [])