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
  • def check_items(current_location, game_items, inventory): ''' (float, dict, list) -> None    Given a float location id...

    def check_items(current_location, game_items, inventory): ''' (float, dict, list) -> None    Given a float location id and a dict of game items, check if any of the game items are found in the current location provided. If they are, add them to the inventory that's provided. The game_items dict has item names as keys, and values as lists with the following information in this order: [description of item, location ID of where the item is found, location ID of where...

  • def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in...

    def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in person_to_clubs belongs to. >>> get_average_club_count(P2C) 1.6 >>> get_average_club_count({'Bob': ['X', 'Y'], 'John': []}) 1.0 """ This is the function I need to test for edge cases, I need to have a test case such that it will detect that the input has been modified(mutation). What test case would I implement?

  • Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture...

    Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture is to be made. def load_locations(filename): (str) -> dict Read data from the file with the given fi lename and create and return a dictionary with location data, structured as descr ibed in the ass ignment handout, Part 1 Section I1 [BEGIN DESCRIPTION There is nothing interesting here [END DESCRIPTION] BEGIN DESCRIPTION] You wake up lost in some unfamiliar place. All you know is...

  • Python help it is a grade 12 course def find astrological sign(month, date): (int, int)-str Given...

    Python help it is a grade 12 course def find astrological sign(month, date): (int, int)-str Given two int values represent ing a month and a date, return a 3-character string that gives us what star sign a person born in that month and on that date belongs to, Use the SIGNS string (already defined for you at the top of this file) to figure this out. NOTE FROM BOB: A lot of string slicing to do here. It looks like...

  • SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a...

    SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' def get_sign_group(sign): ''' (str) -> int Given a three character string representing a star sign, return which group (out of 0, 1, 2, or 3) this star sign belongs to. Use the SIGN_GROUPS string (already defined for you above) to figure out the group. i.e. As given by this string '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN]' the signs ARI, LEO and SAG are in group 0, the signs TAU, VIR, CAP are in group 1, and so on. >>> get_sign_group('ARI') 0 >>>...

  • python: def functionSolver(function: callable)->str You will be given a function as a parameter, the function you...

    python: def functionSolver(function: callable)->str You will be given a function as a parameter, the function you are given only accepts two number parameters and produces a float value. It is your job to figure out what mathematical operation the function you are given is performing by passing it many different parameters. The possible operations the function can perform are: add, subtract, multiply, and divide. The given function will only perform a single operation, it will not change after consecutive invocations....

  • Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can...

    Hey guys I need help with this assignment. However it contains 7 sub-problems to solve but I figured only 4 of them can be solved in one post so I posted the other on another question so please check them out as well :) Here is the questions in this assignment: Note: Two helper functions Some of the testing codes for the functions in this assignment makes use of the print_dict in_key_order (a dict) function which prints dictionary keyvalue pairs...

  • This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string...

    This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) – 'HiHi' string_times('Hi', 3) - 'HiHiHi' string_times('Hi', 1) – 'Hi' Solution: Go Save, Compile, Run (ctrl-enter) Show Solution def string_times (str, n): def string_times(str, n): result = "" for i in range(n): # range(n) is [0, 1, 2, .... n-1] result = result + str...

  • Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all...

    Java StringNode Case Study: Rewrite the following methods in the StringNode class shown below. Leave all others intact and follow similar guidelines. The methods that need to be changed are in the code below. - Rewrite the indexOf() method. Remove the existing recursive implementation of the method, and replace it with one that uses iteration instead. - Rewrite the isPrefix() method so that it uses iteration. Remove the existing recursive implementation of the method, and replace it with one that...

  • Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this...

    Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...

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