Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Binary Deployment

I understand that there are many topics on this but I am having trouble understanding how to make it work. here is my code but I know that the code is incomplete:

# Recruit soldiers and archers to fill out each squadron.
# Each paladin has a decimal number stored in her deployment attribute.
# Convert these to binary and represent them with lines of soldiers and archers next to each paladin.
# Soldiers are 0s, archers are 1s.
# For the bonus goal, add griffins as 2s for trinary number lines next to the warlocks.
# Check the guide for help with binary numbers.

def Dec2Bin(g):
    i=7
    res = []
    while i >= 0:
        res[i] = g // 2**i
        if res[i]:
            g -= 2 ** i
        i -= 1
    return res
binary = Dec2Bin(49)

hero.say("my number is " + binary[7] + " " + binary[6] + " " + binary[5] + " " + binary[4] + " " + binary[3] + " " + binary[2] + " " + binary[1] + " " +  binary[0])


xArr = [15, 20, 25, 30, 35, 40, 45, 50]
def commands(paladin):
    z = binary[7, 6, 5, 4, 3, 2, 1, 0]
    if z == 0:
        hero.summon("soldier")
    elif z == 1:
        hero.summon("archer")
    elif z == 2:
        hero.summon("griffin-rider")
paladin = hero.findNearest(hero.findByType("paladin"))
commands(paladin)

I have got the part of getting the number into binary but I need help on the rest of the level.
just realized I need to call the function

here is my new code

# Each paladin has a decimal number stored in her deployment attribute.
# Convert these to binary and represent them with lines of soldiers and archers next to each paladin.
# Soldiers are 0s, archers are 1s.
# For the bonus goal, add griffins as 2s for trinary number lines next to the warlocks.
# Check the guide for help with binary numbers.

def Dec2Bin(g):
    d=7
    res = []
    while d >= 0:
        res[d] = g // 2**d
        if res[d]:
            g -= 2 ** d
        d -= 1
    return res
#binary = Dec2Bin(49)

#hero.say("my number is " + binary[7] + " " + binary[6] + " " + binary[5] + " " + binary[4] + " " + binary[3] + " " + binary[2] + " " + binary[1] + " " +  binary[0])


xArr = [15, 20, 25, 30, 35, 40, 45, 50]
def commands(paladin):
    g = paladin.deployment
    z = Dec2Bin(g)
    hero.say("my number is " + z)
    friends = hero.findFriends()
    
    for j in range(len(xArr)):
        x = xArr[j]
        hero.command(friends, "move", {'x': x, 'y': paladin.pos.y})
    for i in range(len(z)):
        z1 = z[i]
        if z1 == 0:
            hero.summon("soldier")
        elif z1 == 1:
            hero.summon("archer")
        elif z1 == 2:
            hero.summon("griffin-rider")
paladin = hero.findNearest(hero.findByType("paladin"))
commands(paladin)