0

Right. So I'm making a game. The way I worked it up is you have troops in formations, and these formations are represented in a list. This isn't going to be a complicated matter. I'm not pulling a Total War, least not yet, but I need a way that, if one formation has more troops, the troops loop back around to the start of the opposing list to do their little combat checks


orc1 = orcs.Ogre("Ojjo")
orc2 = orcs.Orc("Durek")
orc3 = orcs.Goblin("Spleesh")

orcform = [orc1,orc2,orc3]

leg1 = imp.Militia("Hans")
leg2 = imp.Archer("Daan")
leg3 = imp.Ballista("The Deathmachine")
leg4 = imp.Slinger("Gus")

impform = [leg1, leg2, leg3, leg4]

def formexchange(attackform, defendform):
    tally = []
    for attacker, defender in zip(attackform, defendform):
        tally.append(exchange(attacker, defender))
    return (tally)

formexchange(impform,orcform)

A few funcs aren't in there, but I think you can get the picture

So this is just a simple zip, obviously. I think this'd be easier if I didn't care to have them fight till everything on one side is dead, but I don't. I need a way to have the impform[3] basically start back at orcform[0] I need to make this repeatable and I need to do this cleanly.... least as clean as possible

Also, ignore the iffy way I'm naming my troops. Already going to fix that with a little name generator

Lurcolm
  • 13
  • 3

1 Answers1

-1

You could do it easily by just popping items off the longer list until its empty

def attack(list1, list2):   
    tally = []   
    if list1 > list2:
        long = list1         
        short = list2
    else:
        long = list2
        short = list1
    try:
        while 1:
            for item in short():
                tally.append(exchange(long.pop(), item))
    except IndexError:
        return tally
Jerome Paddick
  • 399
  • 1
  • 14