0

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}
  1. The Rocs attack the Unicorns for 48 damage (6 * 8), killing one and damaging the next - leaving it with 32/40 hitpoints.
  2. The remaining 3 Unicorns attack the Rocs for 39 damage (3 * 13), killing 0 but leaving the first one with only 1/40 hitpoints.
  3. 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
buran
  • 13,682
  • 10
  • 36
  • 61
  • 1
    `mon2['hitpoints']*mon2['number']-mon1['damage']*mon1['number']` and `mon1['hitpoints']*mon1['number']-mon2['damage']*mon2['number']` do nothing useful. That just returns some value but you don't do anything with it. Nobody's hit points change at all. – ChrisGPT was on strike Feb 12 '22 at 18:59
  • Compare that to what you're doing with `mon2['number']` and `mon1['number']`. – ChrisGPT was on strike Feb 12 '22 at 19:00

0 Answers0