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

Started project #597

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
60 changes: 48 additions & 12 deletions adv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,45 @@

# Fill this out with directions to walk
# traversal_path = ['n', 'n']
traversal_path = []


go_back = {
"n" : "s",
"s" : "n",
"e" : "w",
"w" : "e"
}

def traverse_graph(current_room, visited=None):
# Initialize path
path = []
# create a set of visited rooms if empty
if visited == None:
visited = set()

# Traverse through each exit
for possible_move in player.current_room.get_exits():
# Travel to the next room
player.travel(possible_move)

# If current room is in visited
if player.current_room in visited:
# Use dictionary and current move to go back to previous room
player.travel(go_back[possible_move])
else:
# Add current room to the visited set
visited.add(player.current_room)
# Append the move to the path
path.append(possible_move)
# Recursively call the method passing in the current room and visited set
path = path + traverse_graph(player.current_room, visited)
# Go back to previous room
player.travel(go_back[possible_move])
# Append move to path
path.append(go_back[possible_move])

# At end of loop, return the path
return path

traversal_path = traverse_graph(player.current_room)

# TRAVERSAL TEST - DO NOT MODIFY
visited_rooms = set()
Expand All @@ -51,12 +87,12 @@
#######
# UNCOMMENT TO WALK AROUND
#######
player.current_room.print_room_description(player)
while True:
cmds = input("-> ").lower().split(" ")
if cmds[0] in ["n", "s", "e", "w"]:
player.travel(cmds[0], True)
elif cmds[0] == "q":
break
else:
print("I did not understand that command.")
# player.current_room.print_room_description(player)
# while True:
# cmds = input("-> ").lower().split(" ")
# if cmds[0] in ["n", "s", "e", "w"]:
# player.travel(cmds[0], True)
# elif cmds[0] == "q":
# break
# else:
# print("I did not understand that command.")