Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. #!pip install matplotlib
  2. #!pip install --upgrade pip
  3. # needed for graphics in notebooks:
  4. %matplotlib notebook
  5. # import main code for the game, and all the tests:
  6. import lost_puffling
  7. from lost_puffling_tests import *
  8.  
  9. def all_direction(west, north, east, south):
  10. '''Makes a list with all the directions values for later use.
  11. Values showes how many times a door ha been visited or if the value is None.
  12. '''
  13. direction = [west, north, east, south]
  14. return direction
  15.  
  16. print('all_direction',all_direction(1,0,1,1))
  17.  
  18. def remove_none(west, north, east, south):
  19. '''Calls the list for all_direction, and removes None.
  20. The new list only have values of doors that can be visited.
  21. Doors with value None cant be visited.'''
  22. directions = all_direction(west, north, east, south)
  23. for i in directions:
  24. if i is None:
  25. directions.remove(i)
  26. return directions
  27.  
  28. print('remove_none',remove_none(1,0,None,1))
  29.  
  30. def min_value(west, north, east, south):
  31. '''Calls the new list from remove_none and finds the minimum value.
  32. This is the value of the least visited door is returned.'''
  33. directions = remove_none(west, north, east, south)
  34. least_visited = min(directions)
  35. return least_visited
  36.  
  37. print('min_value',min_value(1,0,None,1))
  38.  
  39. def greedy_direction(west, north, east, south):
  40. '''Calls varible from min_value to compared it to the value of the directions.
  41. returns the direction for the least visited.'''
  42. least_visited = min_value(west, north, east, south)
  43. if least_visited == west:
  44. find_door='west'
  45. if least_visited == north:
  46. find_door='north'
  47. if least_visited == east:
  48. find_door='east'
  49. if least_visited == south:
  50. find_door='south'
  51. return find_door
  52.  
  53. print('greedy_direction',greedy_direction(1,0,1,1))
  54.  
  55. def has_big_key(inventory):
  56. '''Cheks for the big key in inventory. Removes whitespaces og lowercase the str.
  57. If big key is in inventory True is returned else False.'''
  58. inventory = inventory.replace(" ","").lower()
  59. if 'bigkey' in inventory:
  60. return True
  61. return False
  62.  
  63. print('has_big_key = Flase', has_big_key('notb i g k ey'))
  64. print('has_big_key = True', has_big_key(' bigkey '))
  65. print('has_big_key = False', has_big_key('smallkey'))
  66.  
  67. def has_small_key(inventory):
  68. '''Cheks for the small key in inventory. Removes whitespaces og lowercase the str.
  69. If small key is in inventory True is returned else False.'''
  70. inventory = inventory.replace(" ","").lower()
  71. if 'smallkey' in inventory:
  72. return True
  73. return False
  74.  
  75. print('has_small_key = Flase', has_small_key('bigkey'))
  76. print('has_small_key = True',has_small_key('smallkey'))
  77. print('has_small_key = True',has_small_key('s m a l l k e y '))
  78. print('has_small_key = False',has_small_key('not the real s m a l l k e y '))
  79.  
  80. def has_boomerang(inventory):
  81. '''Cheks for boomerang in inventory. Removes whitespaces og lowercase the str.
  82. If boomerang is in inventory True is returned else False.'''
  83. inventory = inventory.replace(" ","").lower()
  84. if 'boomerang' in inventory:
  85. return True
  86. return False
  87.  
  88. print('has_boomerang = True', has_boomerang(' b oo merang'))
  89. print('has_boomerang = False', has_boomerang(' noooo b oo merang'))
  90. print('has_boomerang = Flase', has_boomerang('smallkey'))
  91. print('has_boomerang = True', has_boomerang('boomerang'))
  92.  
  93. def query_decision(inventory, room_info, west, north, east, south):
  94. '''Colletes all funksjons in this one to make all the final decisions.
  95. Finds the least visited door from greedy_direction, this is returned if
  96. none of the other is fulfilled. Calls the funksjouns small_key and boomerang,
  97. if they are True or False. If all the requirements are fulfilled for the big door to open,
  98. return open. And if all the requirements are fulfilled for finding the Big Key, returned boomerang.'''
  99. find_door = greedy_direction(west, north, east, south)
  100. small_key = has_small_key(inventory)
  101. boomerang = has_boomerang(inventory)
  102. if room_info is 'There is a small chest in the room.' and small_key == True:
  103. return 'open'
  104. if room_info is 'You can use the boomerang to get the Big Key.' and boomerang == True:
  105. return 'boomerang'
  106. return find_door
  107.  
  108. print('query_decision',query_decision('','',None,0,1,1))
  109.  
  110. test_all(quiet=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement