Skip to content

Commit

Permalink
Update adv.py
Browse files Browse the repository at this point in the history
  • Loading branch information
br80 authored May 15, 2019
1 parent 2b16aab commit 26a9bf2
Showing 1 changed file with 1 addition and 86 deletions.
87 changes: 1 addition & 86 deletions projects/adventure/adv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,91 +22,6 @@

player = Player("Name", world.startingRoom)

mygraph = {}
traversalPath = []

def opposite(direction):
if direction == 'n':
return 's'
elif direction == 's':
return 'n'
elif direction == 'e':
return 'w'
elif direction == 'w':
return 'e'


def bfs_path(graph, start_room):
queue = []
queue.append([start_room])
visit = set()

while queue:
path = queue.pop(0)
x_room = path[-1]
if x_room not in visit:
visit.add(x_room)
for room_exit in graph[x_room]:
if graph[x_room][room_exit] == '?':
return path
for x in graph[x_room]:
adjacent_room = graph[x_room][x]
new_path = list(path)
new_path.append(adjacent_room)
queue.append(new_path)
return None


while len(mygraph) != len(roomGraph):
current = player.currentRoom.id
if current not in mygraph:
mygraph[current] = {i: '?' for i in player.currentRoom.getExits()}

room_exit = None
for direction in mygraph[current]:
if mygraph[current][direction] == '?':
room_exit = direction
if room_exit is not None:
traversalPath.append(room_exit)
player.travel(room_exit)
discovered = player.currentRoom.id

if discovered not in mygraph:
mygraph[discovered] = {i: '?' for i in player.currentRoom.getExits()}

mygraph[current][room_exit] = discovered
mygraph[discovered][opposite(room_exit)] = current # the value of current
current = discovered # current is now the value of discovered
break

# if there are no unexplored question marks
keys = bfs_path(mygraph, player.currentRoom.id)
print(keys)
if keys is not None:
for room in keys:
for direction in mygraph[current]:
print(f"mg d", mygraph[current])
if mygraph[current][direction] == room:
traversalPath.append(direction)
player.travel(direction)
current = player.currentRoom.id

print(mygraph)
###################################################
# FILL THIS IN

# You have a player. The player can see the exits, but doesn't know the room nums until inside that room.
# You need a create a traversal_graph. keep up with the rooms the player has explored
# When you player enters a room, he will note the exits and add a "?" for a temporary room num.
# You will then have your player randomly choose a "?" to explore.
# On entering the room, the player will update the "?" to the room num
# The player will detect if the room num has already been visited,
# if not, add to visited
# else, back out and visit another room




# TRAVERSAL TEST
visited_rooms = set()
player.currentRoom = world.startingRoom
Expand All @@ -133,4 +48,4 @@ def bfs_path(graph, start_room):
# if cmds[0] in ["n", "s", "e", "w"]:
# player.travel(cmds[0], True)
# else:
# print("I did not understand that command.")
# print("I did not understand that command.")

0 comments on commit 26a9bf2

Please sign in to comment.