Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 61 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. # needed for graphics in notebooks:
  2. %matplotlib notebook
  3. # import main code for the game, and all the tests:
  4. import lost_puffling  
  5. from lost_puffling_tests import *
  6.  
  7.  
  8. def get_damage(technique):
  9.     """Returnerer skaden av angrepsteknikkene"""
  10.     # FEEDBACK: Svært bra
  11.     value = 0
  12.     if technique == 'slash':
  13.         value = 2
  14.     if technique == 'jump slash':
  15.         value = 3
  16.     if technique == 'bow':
  17.         value = 1
  18.     if technique == 'spin attack':
  19.         value = 1.5
  20.     return value
  21.  
  22.  
  23. def choose_technique(enemy):
  24.     """Returnerer angrepsmåte basert på avstanden til motstandaren"""
  25.     # FEEDBACK: Svært bra
  26.     if enemy[1] < 2 and enemy[1] >= 0:
  27.         return 'slash'
  28.     elif enemy[1] < 4 and enemy[1] >= 2:
  29.         return 'jump slash'
  30.     elif enemy[1] >= 4:
  31.         return 'bow'
  32.    
  33. def get_spin_damage(enemies):
  34.     """Returnerer skaden for spin_damage for kvar motstandar i nærleiken"""
  35.     # FEEDBACK: Svært bra
  36.     spin_damage = 0
  37.     for enemy in enemies:
  38.         if 0 <= enemy[1] <= 2:
  39.             spin_damage += min(enemy[0], get_damage("spin attack"))
  40.     return spin_damage
  41.  
  42.  
  43.  
  44. def query_attack(enemies):
  45.     """Tar ei lista av posisjon og avstand til motstandar og returnerer den teknikken som gjer høgast skade"""
  46.     # FEEDBACK: Svært bra
  47.     highest_dmg = 0
  48.     target = None    
  49.     for index, enemy in enumerate(enemies):
  50.         damage = min(enemy[0], get_damage(choose_technique(enemy)))
  51.         if damage > highest_dmg:
  52.             highest_dmg = damage
  53.             target = index
  54.     spin_damage = get_spin_damage(enemies)
  55.     if spin_damage > highest_dmg:
  56.         return ["spin attack", None]
  57.     return [choose_technique(enemies[target]), target]
  58.  
  59. def min_adjoining(adjoining):
  60.     """Returnerer det minst besøkte rommet/romma"""
  61.     # FEEDBACK: Svært bra
  62.    
  63.     coordinates = []    
  64.     # FEEDBACK: Du kan bruke float('inf') i stedet for eit stort tal,
  65.     # men det er kanskje betre å bruke følgende:
  66.     # least_visited = lost_puffling.nvisited(adjoining[0][0], adjoining[0][1])
  67.     least_visited = 100000 #ikkje særlig pent, finns kanskje ein finare måte?
  68.     for (x, y) in (adjoining):
  69.         num_visited = lost_puffling.nvisited(x, y)
  70.         if num_visited < least_visited:
  71.             least_visited = num_visited
  72.             coordinates = [[x, y]]
  73.         elif num_visited == least_visited:
  74.             coordinates.append([x, y])
  75.     return coordinates
  76.  
  77.  
  78. def query_direction(adjoining, inventory):
  79.     """returnerer koordinatene til den raskaste vegen gjennom spelet basert på innhalde i inventaren"""
  80.    
  81.     # FEEDBACK: Svært bra
  82.    
  83.     if len(min_adjoining(adjoining)) > 1:
  84.         # FEEDBACK: Det er betre å bruke denne først, og deretter bruke if len(candidates) > 1
  85.         candidates = min_adjoining(adjoining)
  86.         best_room = candidates[0]
  87.  
  88.         for room in candidates:
  89.            
  90.             if has_big_key(inventory):
  91.                 # FEEDBACK: Du bør ha kommentarer her: størst x, y nær null
  92.                 if room[0] > best_room[0]:
  93.                     best_room = room
  94.                 elif room[0] == best_room[0]:
  95.                     if abs(room[1]) < abs(best_room[1]):
  96.                         best_room = room
  97.                        
  98.             elif has_boomerang(inventory):
  99.                 # Minst y, x nær 0
  100.                 if room[1] < best_room[1]:
  101.                     best_room = room
  102.                 elif room[1] == best_room[1]:
  103.                     if abs(room[0]) < abs(best_room[0]):
  104.                         best_room = room
  105.                            
  106.             elif has_small_key(inventory):
  107.                 # Størst y, x nær 0
  108.                 if room[1] > best_room[1]:
  109.                     best_room = room
  110.                 elif room[1] == best_room[1]:
  111.                     if abs(room[0]) < abs(best_room[0]):
  112.                         best_room = room
  113.                        
  114.             else:
  115.                 # Minst x, y nær 0
  116.                 if room[0] < best_room[0]:
  117.                     best_room = room
  118.                 elif room[0] == best_room[0]:
  119.                     if abs(room[1]) < abs(best_room[1]):
  120.                         best_room = room
  121.         return best_room
  122.    
  123.    
  124.     # Du kan eventuelt flytte dette alternativet øverst, slik at du ser når den blir utført. Altså
  125.     # adjoining = min_adjoining(adjoining)
  126.     # if len(adjoining) == 1:
  127.     #     return adjoining[0]
  128.     # else:
  129.     return min_adjoining(adjoining)[0]  #kanskje ikkje lett å sjå, men dette blir returnert viss ingen av dei øvrige krava blir oppfyllt
  130.  
  131.    
  132.          
  133. def boss_fight():
  134.     """Returnerer optimale avgjerelse basert på avstanden og aggresseviteten til 'bossen'"""
  135.     # FEEDBACK: Svært bra
  136.    
  137.     while lost_puffling.boss_is_alive():
  138.         if lost_puffling.boss_is_attacking():
  139.             lost_puffling.hero_action('dodge')
  140.         else:
  141.             distance = lost_puffling.boss_distance()
  142.             if distance >= 0 and distance < 2:
  143.                 lost_puffling.hero_action('slash')
  144.             if distance < 4 and distance >= 2:
  145.                 lost_puffling.hero_action('jump slash')
  146.             if distance >=4:
  147.                 lost_puffling.hero_action('bow')
  148.        
  149.    
  150.  
  151. def has_item(inventory, item_name):
  152.     '''return True if item_name is in inventory and False otherwise.'''
  153.     inventory = inventory.replace(' ', '').lower()
  154.     item_name = item_name.replace(' ', '').lower()
  155.     return (',' + item_name) in (',' + inventory)
  156.    
  157. def has_big_key(inventory):
  158.     '''return True if the big key is in inventory and False otherwise.'''
  159.     return has_item(inventory, 'big key')
  160.  
  161. def has_small_key(inventory):
  162.     '''return True if the small key is in inventory and False otherwise.'''
  163.     return has_item(inventory, 'small key')
  164.  
  165. def has_boomerang(inventory):
  166.     '''return True if the boomerang is in inventory and False otherwise.'''
  167.     return has_item(inventory, 'boomerang')
  168.  
  169. test_all(quiet=True)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top