Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mvp done #583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/Sprint-Challenge--Graphs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions adv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import random
from ast import literal_eval


# Load world
world = World()

Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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
#######
Expand All @@ -59,4 +84,4 @@
elif cmds[0] == "q":
break
else:
print("I did not understand that command.")
print("I did not understand that command.")