Question

In: Computer Science

The Arrows The hunter can fire arrows. In the classical game, these arrows could turn corners...

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.')

Solutions

Expert Solution

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.')


Related Solutions

Could we turn this java code into a GUI game? Add a orange and a green...
Could we turn this java code into a GUI game? Add a orange and a green trophy object. Orange trophy costs 15 clicks and every time we buy a orange trophy price increases by * 1.09. Green trophy costs 100 clicks and every time we buy a green trophy price increases by * 1.09. Example: you would click the button 15 times in order to be allowed to buy the orange trophy then it resets but then the cost becomes...
Could we turn this java code into a GUI game? Add a orange and a green...
Could we turn this java code into a GUI game? Add a orange and a green trophy object. Orange trophy costs 15 clicks and every time we buy a orange trophy price increases by * 1.09. Green trophy costs 100 clicks and every time we buy a green trophy price increases by * 1.09. Example: you would click the button 15 times in order to be allowed to buy the orange trophy then it resets but then the cost becomes...
Can you light diamond on fire?
Specify the reasons if your answer is YES. Make it in a paragraph form and elaborate it.
Can a food sensitivity turn into an allergy. Explain ?
Can a food sensitivity turn into an allergy. Explain ?
Discuss fire as a mechanism of secondary succession and how a natural fire can enhance species...
Discuss fire as a mechanism of secondary succession and how a natural fire can enhance species diversity of a forest. Use the Intermediate Disturbance Hypothesis.
Lauren has a bow that can shoot arrows at speeds of 0.3c. She is travelling across...
Lauren has a bow that can shoot arrows at speeds of 0.3c. She is travelling across the Great Sandy Desert to her next archery competition on an ultrafast train that moves at a speed of 0.5c. She has set up to practise on the train with a target that is 150 m away from her in the same direction that the train is travelling. Greg is standing on a platform as the train travels by. (a) What is the time...
Lauren has a bow that can shoot arrows at speeds of 0.3c. She is travelling across...
Lauren has a bow that can shoot arrows at speeds of 0.3c. She is travelling across the Great Sandy Desert to her next archery competition on an ultrafast train that moves at a speed of 0.5c. She has set up to practise on the train with a target that is 150 m away from her in the same direction that the train is travelling. Greg is standing on a platform as the train travels by. (a) What is the time...
Suppose that vehicles taking a particular freeway exit can turn right (R), turn left (L), or...
Suppose that vehicles taking a particular freeway exit can turn right (R), turn left (L), or go straight (S). Consider observing the direction for each of three successive vehicles. (Enter your answers in set notation. Enter EMPTY or ∅ for the empty set.) (a) List all outcomes in the event A that all three vehicles go in the same direction. A =      (b) List all outcomes in the event B that all three vehicles take different directions. B =  ...
Discuss the Classical Gold Standard and critically explain how following “the rules of the game” creates...
Discuss the Classical Gold Standard and critically explain how following “the rules of the game” creates a price-flow mechanism capable of correcting international payments imbalances. Word Count (500 words)    
how could an increase in voter turn out throughout the state and especially among Latinos in...
how could an increase in voter turn out throughout the state and especially among Latinos in young people influence the public policy priorities of the state legislature and the plural executive?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT