In: Computer Science
The Arrows
The hunter can fire arrows. In the classical game, these arrows could turn corners and clear several rooms at a time, and were limited to 5. In this version, for simplicity we'll allow unlimited arrows but only shoot into one room at a time.
Compose a function shoot_arrow which accepts a cave, a hunter (int), a wumpus (int), and a string command action of the form 's 5' for "shoot into room #5", and prints a success message and exit()s if the Wumpus is slain.
Language: Python
Start Code
def shoot_arrow(cave,hunter,wumpus,action): # Process `action` into two pieces, the second being the room (`int`). # Make sure that the target room is valid (that is, connected to the room the hunter is in). if _____: print('Invalid move, that room is not connected.') # Check whether the Wumpus is in the same room as the target. if _____: print('Frabjous day! Thou hast slain the Wumpus and freed these lands from its foul presence. Thou are hailed a knight of the realm!') exit() else: print('Thou hast erred in thy aim.')
def shoot_arrow(cave,hunter,wumpus,action):
target=int(action.split()[1])
# Process `action` into two pieces, the second being the room
(`int`).
# Make sure that the target room is valid (that is, connected to
the room the hunter is in).
if target not in cave[hunter]:
print('Invalid move, that room is not connected.')
# Check whether the Wumpus is in the same room as the target.
elif target==wumpus:
print('Frabjous day! Thou hast slain the Wumpus and freed these
lands from its foul presence. Thou are hailed a knight of the
realm!')
exit()
else:
print('Thou hast erred in thy aim.')