I would like to simulate a battle of monsters from Heroes Might & Magic. The problem is that only my monster no.2 (unicorn) loss his points. What I'm doing wrong ?
Fighting mechanics explanation:
mon1 = {"type": "Roc", "hitpoints": 40, "number": 6, "damage":8 }
mon2 = {"type": "Unicorn", "hitpoints": 40, "number": 4, "damage":13}
- The Rocs attack the Unicorns for 48 damage (6 * 8), killing one and damaging the next - leaving it with 32/40 hitpoints.
- The remaining 3 Unicorns attack the Rocs for 39 damage (3 * 13), killing 0 but leaving the first one with only 1/40 hitpoints.
- Repeat until one of the groups is left with 0 units in total.
code
import math
def who_would_win(mon1, mon2):
mon1 = {'type': "Roc", 'hitpoints': 40, 'number': 6, 'damage' : 8 }
mon2 = {'type': "Unicorn", 'hitpoints': 40, 'number': 4, 'damage' : 13}
while mon1['number'] > 0 and mon2['number'] > 0:
mon2['hitpoints']*mon2['number']-mon1['damage']*mon1['number']
mon2['number'] = int(math.ceil((mon2['hitpoints']*mon2['number']-mon1['damage']*mon1['number'])/mon2['hitpoints']))
mon1['hitpoints']*mon1['number']-mon2['damage']*mon2['number']
mon1['number'] = int(math.ceil((mon1['hitpoints']*mon1['number']-mon2['damage']*mon2['number'])/mon1['hitpoints']))
if mon1['number'] > 0 and mon2['number'] <= 0:
return (f'{mon1["number"]} {mon1["type"]}(s) won')
if mon2['number'] > 0 and mon1['number'] <= 0:
return (f'{mon2["number"]} {mon2["type"]}(s) won')
else:
continue