diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 000000000..8be72f162
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/../../../../../../../:\Users\Tootsie\Desktop\Lambda\Sprint-Challenge--Graphs\.idea/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/Sprint-Challenge--Graphs.iml b/.idea/Sprint-Challenge--Graphs.iml
new file mode 100644
index 000000000..d0876a78d
--- /dev/null
+++ b/.idea/Sprint-Challenge--Graphs.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 000000000..105ce2da2
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..d1e22ecb8
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 000000000..43cc29839
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..94a25f7f4
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/adv.py b/adv.py
index 84f031836..e911797ce 100644
--- a/adv.py
+++ b/adv.py
@@ -5,6 +5,7 @@
import random
from ast import literal_eval
+
# Load world
world = World()
@@ -17,7 +18,7 @@
map_file = "maps/main_maze.txt"
# Loads the map into a dictionary
-room_graph=literal_eval(open(map_file, "r").read())
+room_graph = literal_eval(open(map_file, "r").read())
world.load_graph(room_graph)
# Print an ASCII map
@@ -29,7 +30,32 @@
# traversal_path = ['n', 'n']
traversal_path = []
+# keep track of "reverse" directions
+# use this to return to a room with valid moves
+backtrack = []
+reversed_directions = {'n': 's', 's': 'n', 'e': 'w', 'w': 'e'}
+
+# instantiate a set to keep track of visited rooms
+visited = set()
+
+# while there are still unvisited rooms
+while len(visited) < len(room_graph):
+ next_move = None
+ # for each exit(neighbor) in the room expressed by (n,s,e,w)
+ for exit in player.current_room.get_exits():
+ if player.current_room.get_room_in_direction(exit) not in visited:
+ next_move = exit
+ break
+ if next_move is not None:
+ traversal_path.append(next_move)
+ backtrack.append(reversed_directions[next_move])
+ player.travel(next_move)
+ visited.add(player.current_room)
+ else:
+ next_move = backtrack.pop()
+ traversal_path.append(next_move)
+ player.travel(next_move)
# TRAVERSAL TEST - DO NOT MODIFY
visited_rooms = set()
@@ -41,13 +67,12 @@
visited_rooms.add(player.current_room)
if len(visited_rooms) == len(room_graph):
- print(f"TESTS PASSED: {len(traversal_path)} moves, {len(visited_rooms)} rooms visited")
+ print(
+ f"TESTS PASSED: {len(traversal_path)} moves, {len(visited_rooms)} rooms visited")
else:
print("TESTS FAILED: INCOMPLETE TRAVERSAL")
print(f"{len(room_graph) - len(visited_rooms)} unvisited rooms")
-
-
#######
# UNCOMMENT TO WALK AROUND
#######
@@ -59,4 +84,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