fork download
  1. def aimed(player_attributes, enemy_attributes):
  2. branch_taken = 0
  3. if player_attributes['endurance'] < enemy_attributes['endurance'] // 10 * 10:
  4. branch_taken = 1
  5. player_attributes['endurance'] += 1
  6. else:
  7. branch_taken = 2
  8. for attribute in enemy_attributes:
  9. if player_attributes[attribute] <= enemy_attributes[attribute] // 2:
  10. player_attributes[attribute] += 1
  11. equated = False
  12. break
  13. else:
  14. equated = True
  15.  
  16. if equated:
  17. branch_taken = 3
  18. for attribute in enemy_attributes:
  19. if enemy_attributes[attribute] == min(enemy_attributes.values()):
  20. player_attributes[attribute] += 1
  21. break
  22.  
  23. return player_attributes, branch_taken
  24.  
  25. def stats_dict(endurance, strength, agility, speed):
  26. return {'endurance': endurance, 'strength': strength, 'agility': agility, 'speed': speed}
  27.  
  28. def stats_to_string(stats):
  29. return "(END {endurance}, STR {strength}, AGI {agility}, SPD {speed})".format(**stats)
  30.  
  31. def test(player_endurance, player_strength, player_agility, player_speed,
  32. enemy_endurance, enemy_strength, enemy_agility, enemy_speed):
  33. player = stats_dict(player_endurance, player_strength, player_agility, player_speed)
  34. enemy = stats_dict(enemy_endurance, enemy_strength, enemy_agility, enemy_speed)
  35. aimed_result, branch_taken = aimed(player.copy(), enemy)
  36. print("aim {0} to {1}: {2}, b#{3}".format(stats_to_string(player), stats_to_string(enemy), stats_to_string(aimed_result), branch_taken))
  37.  
  38. # Вторая ветка — увеличение «недостающего» атрибута
  39. test(99, 3, 3, 3, 99, 9, 9, 9)
  40. test(99, 8, 8, 8, 99, 20, 20, 20)
  41.  
  42. # Третья ветка — увеличение атрибута, соответствующего худшему атрибуту врага
  43. test(99, 3, 3, 3, 99, 4, 4, 4)
  44. test(99, 8, 8, 8, 99, 9, 9, 9)
Success #stdin #stdout 0.01s 28384KB
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 3, AGI 3, SPD 4), b#2
aim (END 99, STR 8, AGI 8, SPD 8) to (END 99, STR 20, AGI 20, SPD 20): (END 99, STR 8, AGI 8, SPD 9), b#2
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), b#3
aim (END 99, STR 8, AGI 8, SPD 8) to (END 99, STR 9, AGI 9, SPD 9): (END 99, STR 8, AGI 8, SPD 9), b#3