Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!pip install matplotlib
- #!pip install --upgrade pip
- # needed for graphics in notebooks:
- %matplotlib notebook
- # import main code for the game, and all the tests:
- import lost_puffling
- from lost_puffling_tests import *
- def all_direction(west, north, east, south):
- '''Makes a list with all the directions values for later use.
- Values showes how many times a door ha been visited or if the value is None.
- '''
- direction = [west, north, east, south]
- return direction
- print('all_direction',all_direction(1,0,1,1))
- def remove_none(west, north, east, south):
- '''Calls the list for all_direction, and removes None.
- The new list only have values of doors that can be visited.
- Doors with value None cant be visited.'''
- directions = all_direction(west, north, east, south)
- for i in directions:
- if i is None:
- directions.remove(i)
- return directions
- print('remove_none',remove_none(1,0,None,1))
- def min_value(west, north, east, south):
- '''Calls the new list from remove_none and finds the minimum value.
- This is the value of the least visited door is returned.'''
- directions = remove_none(west, north, east, south)
- least_visited = min(directions)
- return least_visited
- print('min_value',min_value(1,0,None,1))
- def greedy_direction(west, north, east, south):
- '''Calls varible from min_value to compared it to the value of the directions.
- returns the direction for the least visited.'''
- least_visited = min_value(west, north, east, south)
- if least_visited == west:
- find_door='west'
- if least_visited == north:
- find_door='north'
- if least_visited == east:
- find_door='east'
- if least_visited == south:
- find_door='south'
- return find_door
- print('greedy_direction',greedy_direction(1,0,1,1))
- def has_big_key(inventory):
- '''Cheks for the big key in inventory. Removes whitespaces og lowercase the str.
- If big key is in inventory True is returned else False.'''
- inventory = inventory.replace(" ","").lower()
- if 'bigkey' in inventory:
- return True
- return False
- print('has_big_key = Flase', has_big_key('notb i g k ey'))
- print('has_big_key = True', has_big_key(' bigkey '))
- print('has_big_key = False', has_big_key('smallkey'))
- def has_small_key(inventory):
- '''Cheks for the small key in inventory. Removes whitespaces og lowercase the str.
- If small key is in inventory True is returned else False.'''
- inventory = inventory.replace(" ","").lower()
- if 'smallkey' in inventory:
- return True
- return False
- print('has_small_key = Flase', has_small_key('bigkey'))
- print('has_small_key = True',has_small_key('smallkey'))
- print('has_small_key = True',has_small_key('s m a l l k e y '))
- print('has_small_key = False',has_small_key('not the real s m a l l k e y '))
- def has_boomerang(inventory):
- '''Cheks for boomerang in inventory. Removes whitespaces og lowercase the str.
- If boomerang is in inventory True is returned else False.'''
- inventory = inventory.replace(" ","").lower()
- if 'boomerang' in inventory:
- return True
- return False
- print('has_boomerang = True', has_boomerang(' b oo merang'))
- print('has_boomerang = False', has_boomerang(' noooo b oo merang'))
- print('has_boomerang = Flase', has_boomerang('smallkey'))
- print('has_boomerang = True', has_boomerang('boomerang'))
- def query_decision(inventory, room_info, west, north, east, south):
- '''Colletes all funksjons in this one to make all the final decisions.
- Finds the least visited door from greedy_direction, this is returned if
- none of the other is fulfilled. Calls the funksjouns small_key and boomerang,
- if they are True or False. If all the requirements are fulfilled for the big door to open,
- return open. And if all the requirements are fulfilled for finding the Big Key, returned boomerang.'''
- find_door = greedy_direction(west, north, east, south)
- small_key = has_small_key(inventory)
- boomerang = has_boomerang(inventory)
- if room_info is 'There is a small chest in the room.' and small_key == True:
- return 'open'
- if room_info is 'You can use the boomerang to get the Big Key.' and boomerang == True:
- return 'boomerang'
- return find_door
- print('query_decision',query_decision('','',None,0,1,1))
- test_all(quiet=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement