From 76f96139f74cf1e3a34c8b42c63d442a510e9559 Mon Sep 17 00:00:00 2001 From: Enayatullah Date: Fri, 20 Nov 2020 19:40:54 -0800 Subject: [PATCH 1/2] Main path --- adv.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/adv.py b/adv.py index 84f031836..d9e0d3654 100644 --- a/adv.py +++ b/adv.py @@ -5,33 +5,27 @@ import random from ast import literal_eval -# Load world world = World() -# You may uncomment the smaller graphs for development and testing purposes. -# map_file = "maps/test_line.txt" -# map_file = "maps/test_cross.txt" -# map_file = "maps/test_loop.txt" -# map_file = "maps/test_loop_fork.txt" map_file = "maps/main_maze.txt" -# Loads the map into a dictionary room_graph=literal_eval(open(map_file, "r").read()) world.load_graph(room_graph) -# Print an ASCII map world.print_rooms() player = Player(world.starting_room) -# Fill this out with directions to walk -# traversal_path = ['n', 'n'] traversal_path = [] +visited = {} + +my_path = [] + +back_direction = {'n': 's', 's': 'n', 'e': 'w', 'w': 'e'} -# TRAVERSAL TEST - DO NOT MODIFY visited_rooms = set() player.current_room = world.starting_room visited_rooms.add(player.current_room) @@ -59,4 +53,4 @@ elif cmds[0] == "q": break else: - print("I did not understand that command.") + print("I did not understand that command.") \ No newline at end of file From e40e4be41e7b70b285e06e6fd920a162a0dc341a Mon Sep 17 00:00:00 2001 From: Enayatullah Date: Mon, 30 Nov 2020 11:10:07 -0800 Subject: [PATCH 2/2] MVP --- .vs/Sprint-Challenge--Graphs/v16/.suo | Bin 0 -> 15360 bytes .vs/VSWorkspaceState.json | 8 +++ .vs/slnx.sqlite | Bin 0 -> 90112 bytes adv.py | 76 +++++++++++++++++++++++--- 4 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 .vs/Sprint-Challenge--Graphs/v16/.suo create mode 100644 .vs/VSWorkspaceState.json create mode 100644 .vs/slnx.sqlite diff --git a/.vs/Sprint-Challenge--Graphs/v16/.suo b/.vs/Sprint-Challenge--Graphs/v16/.suo new file mode 100644 index 0000000000000000000000000000000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SJBshUmz4O3x{4O0z0AyW1!|y1mi^i`rIcN3LS{g>k}%Vlnn5 z%WjFC^Z=$KTe*9W$v~g)rS?1S4pygZyi--y1o$ceIbaW$EPke>)PH&AFW| zz#eYhKuz85?Lx$+7o89m#oq9;#o+P(INJ1fp6vTl`kvF#AdeS6a&+g{GPF1^T5P#e z!;2qy@#D63I__`^W?a|!@w@mzpZ~}E|L^)n2Uds#kN^@u0!RP}AOR$R1dsp{KmthM zt`flY|6Rq6l_3EnfCP{L5VvLpvOv)01`j~NB{{S z0VIF~kN^@u0!RP}+%*Dt{r|3^#)^;t5 0: + return self.stack.pop() + else: + return None + def size(self): + return len(self.stack) + +# Load world world = World() - +# You may uncomment the smaller graphs for development and testing purposes. +# map_file = "maps/test_line.txt" +# map_file = "maps/test_cross.txt" +# map_file = "maps/test_loop.txt" +# map_file = "maps/test_loop_fork.txt" map_file = "maps/main_maze.txt" +# Loads the map into a dictionary room_graph=literal_eval(open(map_file, "r").read()) world.load_graph(room_graph) +# Print an ASCII map world.print_rooms() player = Player(world.starting_room) +# Fill this out with directions to walk +# traversal_path = ['n', 'n'] traversal_path = [] -visited = {} - -my_path = [] - -back_direction = {'n': 's', 's': 'n', 'e': 'w', 'w': 'e'} - +# Path +def shortest_path(direction): + + if direction == "n": + return "s" + elif direction == "s": + return "n" + elif direction == "e": + return "w" + elif direction == "w": + return "e" + + ##L +paths = Stack() +visited = set() + +while len(visited) < len(world.rooms): + exits = player.current_room.get_exits() + path = [] + + for exit in exits: + if exit is not None and player.current_room.get_room_in_direction(exit) not in visited: + path.append(exit) + + visited.add(player.current_room) + ##r + if len(path) > 0: + move = random.randint(0, len(path) -1) + paths.push(path[move]) + player.travel(path[move]) + traversal_path.append(path[move]) + + ##e + else: + end = paths.pop() + player.travel(shortest_path(end)) + traversal_path.append(shortest_path(end)) +# TRAVERSAL TEST - DO NOT MODIFY visited_rooms = set() player.current_room = world.starting_room visited_rooms.add(player.current_room) @@ -42,6 +99,7 @@ + ####### # UNCOMMENT TO WALK AROUND ####### @@ -53,4 +111,6 @@ elif cmds[0] == "q": break else: - print("I did not understand that command.") \ No newline at end of file + print("I did not understand that command.") + +##Test pass \ No newline at end of file