fork download
  1. import random
  2.  
  3. def aimed(player_attributes, enemy_attributes):
  4. if player_attributes['endurance'] < enemy_attributes['endurance'] // 10 * 10:
  5. player_attributes['endurance'] += 1
  6. else:
  7. underleveled_attrs = list(attr for attr in player_attributes if player_attributes[attr] <= enemy_attributes[attr] // 2)
  8. if underleveled_attrs:
  9. player_attributes[random.choice(underleveled_attrs)] += 1
  10. else:
  11. worst_enemy_attr_value = min(enemy_attributes.values())
  12. worst_enemy_attrs = list(attr for attr in enemy_attributes if enemy_attributes[attr] == worst_enemy_attr_value)
  13. player_attributes[random.choice(worst_enemy_attrs)] += 1
  14.  
  15. return player_attributes
  16.  
  17. def stats_dict(endurance, strength, agility, speed):
  18. return {'endurance': endurance, 'strength': strength, 'agility': agility, 'speed': speed}
  19.  
  20. def stats_to_string(stats):
  21. return "(END {endurance}, STR {strength}, AGI {agility}, SPD {speed})".format(**stats)
  22.  
  23. def test(player_endurance, player_strength, player_agility, player_speed,
  24. enemy_endurance, enemy_strength, enemy_agility, enemy_speed):
  25. player = stats_dict(player_endurance, player_strength, player_agility, player_speed)
  26. enemy = stats_dict(enemy_endurance, enemy_strength, enemy_agility, enemy_speed)
  27. aimed_result = aimed(player.copy(), enemy)
  28. print("aim {0} to {1}: {2}".format(stats_to_string(player), stats_to_string(enemy), stats_to_string(aimed_result)))
  29.  
  30. test(99, 3, 3, 3, 99, 9, 9, 9)
  31. test(99, 8, 8, 8, 99, 20, 20, 20)
  32. test(99, 3, 3, 3, 99, 4, 4, 4)
  33. test(99, 8, 8, 8, 99, 9, 9, 9)
Success #stdin #stdout 0.02s 36952KB
stdin
Standard input is empty
stdout
aim (END 99, STR 3, AGI 3, SPD 3) to (END 99, STR 9, AGI 9, SPD 9): (END 99, STR 4, AGI 3, SPD 3)
aim (END 99, STR 8, AGI 8, SPD 8) to (END 99, STR 20, AGI 20, SPD 20): (END 99, STR 8, AGI 9, SPD 8)
aim (END 99, STR 3, AGI 3, SPD 3) to (END 99, STR 4, AGI 4, SPD 4): (END 99, STR 3, AGI 3, SPD 4)
aim (END 99, STR 8, AGI 8, SPD 8) to (END 99, STR 9, AGI 9, SPD 9): (END 99, STR 9, AGI 8, SPD 8)