Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. import json
  2.  
  3.  
  4. def return_max_health(s):
  5.  
  6. if s == 'Sorceress':
  7. return 50
  8. if s == 'Knight':
  9. return 100
  10. if s == 'Barbarian':
  11. return 120
  12. if s == 'Warlock':
  13. return 70
  14.  
  15.  
  16. s = input()
  17.  
  18. dict = json.loads(s)
  19.  
  20. for i in range(0, len(dict['battle_steps']), 1):
  21.  
  22. dict_step = dict['battle_steps'][i]
  23. action = dict_step['action']
  24. power = dict_step['power']
  25. id_to = dict_step['id_to']
  26. id_from = dict_step['id_from']
  27.  
  28. id_to_health = dict['armies'][id_to]['health']
  29. id_from_health = dict['armies'][id_from]['health']
  30.  
  31. if id_to_health <= 0 or id_from_health <= 0:
  32. continue
  33.  
  34. if action == 'attack':
  35.  
  36. dict['armies'][id_to]['defence'] -= power
  37. dict['armies'][id_from]['attack'] -= power
  38. if dict['armies'][id_to]['defence'] < 0:
  39. new_defence = dict['armies'][id_to]['defence']
  40. dict['armies'][id_to]['health'] += new_defence
  41. dict['armies'][id_to]['defence'] = 0
  42. new_health = dict['armies'][id_to]['health']
  43. if new_health <= 0:
  44. dict['armies'][id_from]['experience'] += 5
  45. dict['armies'][id_to]['health'] = 0
  46. else:
  47. dict['armies'][id_from]['experience'] += 1
  48. dict['armies'][id_to]['experience'] += 1
  49. else:
  50. dict['armies'][id_from]['experience'] += 1
  51. dict['armies'][id_to]['experience'] += 1
  52.  
  53. if action == 'cast_damage_spell':
  54.  
  55. dict['armies'][id_to]['defence'] -= power
  56. dict['armies'][id_from]['mana'] -= power
  57. if dict['armies'][id_to]['defence'] < 0:
  58. new_defence = dict['armies'][id_to]['defence']
  59. dict['armies'][id_to]['health'] += new_defence
  60. dict['armies'][id_to]['defence'] = 0
  61. new_health = dict['armies'][id_to]['health']
  62. if new_health <= 0:
  63. dict['armies'][id_from]['experience'] += 5
  64. dict['armies'][id_to]['health'] = 0
  65. else:
  66. dict['armies'][id_from]['experience'] += 1
  67. dict['armies'][id_to]['experience'] += 1
  68. else:
  69. dict['armies'][id_from]['experience'] += 1
  70. dict['armies'][id_to]['experience'] += 1
  71.  
  72. if action == 'cast_health_spell':
  73.  
  74. new_health = dict['armies'][id_to]['health'] + power
  75. max_health = return_max_health(dict['armies'][id_to]['race'])
  76. dict['armies'][id_to]['health'] = min(new_health, max_health)
  77. dict['armies'][id_from]['experience'] += 1
  78. dict['armies'][id_from]['mana'] -= power
  79.  
  80.  
  81. ronald_points = 0
  82. archibald_points = 0
  83. ronald_alive = False
  84. archibald_alive = False
  85.  
  86. for i in dict['armies']:
  87.  
  88. heroe = dict['armies'][i]
  89.  
  90. if heroe['health'] > 0:
  91.  
  92. points = 0
  93. points += heroe['experience']
  94. points += 2*heroe['defence']
  95. points += 3*heroe['attack']
  96.  
  97. if 'mana' in heroe:
  98. points += 10*heroe['mana']
  99.  
  100. if heroe['lord'] == 'Archibald':
  101. archibald_alive = True
  102. archibald_points += points
  103. else:
  104. ronald_alive = True
  105. ronald_points += points
  106.  
  107.  
  108. if ronald_alive and archibald_alive:
  109.  
  110. if ronald_points > archibald_points:
  111. print('Ronald')
  112.  
  113. if ronald_points < archibald_points:
  114. print('Archibald')
  115.  
  116. if ronald_points == archibald_points:
  117. print('unknown')
  118.  
  119. else:
  120. if ronald_alive:
  121. print('Ronald')
  122.  
  123. if archibald_alive:
  124. print('Archibald')
  125.  
  126. if ronald_alive is False and archibald_alive is False:
  127. print('unknown')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement