Question

def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data...

def do_action(decision, game_data, current_location, inventory):
'''
(int, dict, float, list) -> str

Given the game data dict, and the current location ID, get
all the possible actions at that location.

If the decision number given as 'decision' falls outside the number
of allowed actions at this location, then return the string
"Invalid decision. Please select choice from the decisions listed."
Make sure this string is EXACTLY as above.

Else, if the decision is valid, then figure out the location information
of the new location ID that the player should end up at after
doing this decision (use game_data, current_location, and the decision
chosen to figure this out).

Check for any items at this new location and add to inventory (remember you
can call already existing functions to make your code shorter
and less repetitive).

Return the text description of the new location ID where you end up
after doing this action (e.g. the same way that visit_location function
returns text description of visited location).
'''

# YOUR CODE HERE #
pass

#python

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per your given data and with some assumptions i have created the function. You just have to edit some of it according of the rest of the functions that you have. Here is the code:

valid_nums = list() # List of valid decisions

def do_action(decision, game_data, current_location, inventory):

inventory = list() # Inventory with items

game_data = dict() # Dictionary with game data

new_location = None # New_location

if decision not in valid_nums:

return "Invalid decision. Please select choice from the decisions listed."

else:

# Assuming you habe game_data have keys as decision number and values as locations

for i in game_data.keys():

if decision == i:

new_location = game_data[i]

# Assuming you have a function already for the inventory search

if find_item(new_location) != None:

inventory.append(find_item(new_location))

return visit_location(new_location)

Thank you.

Add a comment
Know the answer?
Add Answer to:
def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT