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

Graphs Challenge #589

Open
wants to merge 2 commits 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
Binary file added .vs/Sprint-Challenge--Graphs/v16/.suo
Binary file not shown.
8 changes: 8 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ExpandedNodes": [
"",
"\\maps"
],
"SelectedNode": "\\adv.py",
"PreviewInSolutionExplorer": false
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
58 changes: 56 additions & 2 deletions adv.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
#Enayatullah N.

from room import Room
from player import Player
from world import World

import random
from ast import literal_eval

#Stack class
class Stack():
def __init__(self):
self.stack = []
def push(self, value):
self.stack.append(value)
def pop(self):
if self.size() > 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"
Expand All @@ -29,7 +44,43 @@
# traversal_path = ['n', 'n']
traversal_path = []


# 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()
Expand All @@ -48,6 +99,7 @@




#######
# UNCOMMENT TO WALK AROUND
#######
Expand All @@ -60,3 +112,5 @@
break
else:
print("I did not understand that command.")

##Test pass