Summit gate! HELP!

summonTypes = ['griffin-rider''archer']
tactick = 'hold'
stage = 1




def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")


def lowestHealthPaladin():
    lowestHealth = 99999
    lowestFriend = None
    friends = hero.findFriends()
    for friend in friends:
        if friend.health < lowestHealth and friend.health < friend.maxHealth:
            lowestHealth = friend.health
            lowestFriend = friend
    return lowestFriend


def commandPaladin(paladin):
    if (paladin.canCast("heal")):
        if (hero.health < hero.maxHealth * 0.8):
            target = self
        else:
            target = lowestHealthPaladin()
        if target:
            hero.command(paladin, "cast", "heal", target)
    elif (paladin.health < 100):
        hero.command(paladin, "shield")
    elif stage < 4:
        hero.command(paladin, "move", {'x': 94, 'y': 34})
    elif stage == 5:
        hero.command(paladin, "move", {'x': 284, 'y': 33})
    else:
        target = hero.findNearestEnemy()
        if (warlock):
            target = warlock
        if (target):
            hero.command(paladin, "attack", target)


def commandSoldier(soldier):
    target = hero.findNearestEnemy()
    if (warlock):
        target = warlock
    if stage == 3:
        hero.command(soldier, "move", {'x': 84, 'y': 34})
    elif (target):
        hero.command(soldier, "attack", target)


def commandFriends():
    friends = hero.findFriends()
    for friend in friends:
        if tactick == 'hold':
            hero.command(friend, "defend", {'x': 1, 'y': 40})
        elif friend.type == "paladin":
            commandPaladin(friend)
        else:
            commandSoldier(friend)


def moveTo(position):
    if (hero.isReady("jump")):
        hero.jumpTo(position)
    else:
        hero.move(position)


def attack(target):
    if target:
        if (hero.distanceTo(target) > 10):
            moveTo(target.pos)
        else:
            hero.attack(target)


def pickUpNearestItem():
    nearestItem = hero.findNearestItem()
    if nearestItem:
        moveTo(nearestItem.pos)


commandFriends()
hero.moveXY(31, 56)
while True:
    catapult = hero.findNearest(hero.findByType('catapult'))
    warlock = hero.findNearest(hero.findByType('warlock'))
    target = hero.findNearestEnemy()
    nearestItem = hero.findNearestItem()
    now = hero.now()
    if catapult:
        stage = 1
        attack(catapult)
    elif now < 20:
        tactick = 'defend'
        stage = 2
        moveTo({"x": 50, "y": 33})
    elif stage < 4:
        if target:
            stage = 3
            attack(target)
        else:
            moveTo({"x": 172, "y": 46})
        if hero.pos.x > 170:
            stage = 4
    elif stage < 5:
        if hero.pos.x < 240:
            moveTo({"x": 274, "y": 35})
            tactick = 'defend'
        elif nearestItem and hero.distanceTo(nearestItem) < 10:
            pickUpNearestItem()
            tactick = 'attack'
        elif (warlock):
            target = warlock
            summonTroops()
            attack(target)
        elif target and target.type == 'gates':
            attack(target)
        elif nearestItem and hero.distanceTo(nearestItem) < 45:
            pickUpNearestItem()
            tactick = 'defend'
            summonTroops()
        else:
            attack(target)
        if hero.pos.x > 290:
            stage = 5
        tactick = 'attack'
    else:
        summonTroops()
        attack(target)
    commandFriends()
    hero.attack

What is the correct code? i can’t solve it on my own d

What’s your current equipment? I’ll need to see it first so i can give you some tips

I will need to get on my chromebook first1

Dont worry i’ll wait

image
this is my equipment.

There’s no correct code for this level. You can win in many different ways with many different equipments.
If you don’t have a specific problem or error, or something you can’t do (other than winning) then I’m afraid I can’t help you. You’ll have to spend a lot of time trying to solve it I’m afraid. It is the end of the Mountain and the gateway to the Glacier after all!
Danny

I’d check your summon types, it looks like you have the type variable defined to alternate between griffin-riders and archers, but the way the code is written it will only summon archers because the actual summoning doesn’t reference type:

def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf("griffin-rider"):
        hero.summon("griffin-rider")
    if hero.gold > hero.costOf("archer"):
        hero.summon("archer")

Each cycle this checks to see if there is enough gold to summon a grifin-rider and summons if it can. Then it checks to see if there’s enough money to summon an archer and summons if it can. The problem is that you will always have enough for an archer before you have enough for a griffin-rider, so the archer will always summon first, taking away gold, and you’ll never have enough for a griffin-rider. Try instead

def summonTroops():
    type = summonTypes[len(hero.built) % len(summonTypes)]
    if hero.gold > hero.costOf(type):
        hero.summon(type)

This is just the first thing that jumped out at me, there may be other issues, weed through your code and keep trying!

This is a pretty difficult level considering your class, Is this a free account? because if so, i can’t use the same strategy i have, since i used a mage class. but I’ll give you some tips

For the first part, split your soldiers into two parts, one goes for the top catapult and one goes to the bottom catapult. Since the soldiers are faster than most of the enemies the enemies will end up tailing the soldiers, leading to their doom, as the catapult’s fire goes behind the soldiers. unfortunately this is also a suicide mission for them, some might live if you command them to move

Make your archers defend the hero and make the paladins heal the archers and your hero. this way you can break the door down after all the enemies are down.

Once you break the door, move back to the fields a little, as munchkins will spawn

After killing the munchkins move to the right and you will see two energy towers. You will need to destroy them since you have to defeat all “ogres” You can do this by:

  1. make your paladins focus healing on the hero, and solo the towers. make sure you are at the right position to attack because the towers have limited range.

  2. or you can ignore the towers at first and break the second door down. doing this will summon more soldiers and then you can command them to destroy the towers

once you reach the third door you will find two warlocks guarding some gems. focus you attacks on them and not the skeletons they spawn.

The warlocks explode when killed, so make sure your paladins keep up the healing

once you do that defeat the second warlock, collect the gems, summon soldiers, and break the door to attack the remaining ogres. But make sure your troops attack the witch first, as the witch can heal enemies.

Hope this helps
Riley

Just tried the code with a similar loadout and found one more bug in your summoning:

 summonTypes = ['griffin-rider''archer'] # <-- missing comma
 tactick = 'hold'
 stage = 1

with those changes it might work (barely)

Also I would recommend you implement your invisibility to approach the towers and get the paladins to heal each other when they’re not healing you

Well I have alot of trouble with improvising. What code do you find works the best?

Can you show me how to do the two things you are talking about?

@Mr_Berg, welcome back! :tada:

HOw? do i do that ???

also is there a way to get a free subscription?

No, it would be cool, but it wouldn’t be a very good business model for CodeCombat if they made no money. :grin:
And it would mean they wouldn’t be able to support the free campaign, so it really relies on the subscribers to make it work.
Danny

well I can’t think of anything else to try. So how will i be able to get further?

I’m sure you’ll be able to do this level at some point. How long have you been trying? I sometimes had to do levels for weeks, spending a lot of time on it every day.
Why not use flags?
Danny

FOR A WHOLE WEEK. ANd it would be easier if i could just find one way to BEAT IT! also I don’t know what code to use for the flags

This is an example of some good flag code, using different colours:

flagGreen = hero.findNearestFlag("green")
flagBlack = hero.findNearestFlag("black")
flagViolet = hero.findNearestFlag("violet")
if flagGreen:
    hero.pickUp(flagGreen)
elif flagBlack:
    hero.buildXY("fire-trap", flagBlack.pos.x, flagBlack.pos.y)
    hero.remove(flagBlack) # you need advanced flags for this
elif flagViolet:
    enemy = hero.findNearestEnemy()
    if enemy.health < 0:
        hero.remove(flagViolet)
    elif enemy:
        hero.attack(enemy)
    else:
        hero.remove(flagViolet)

here, I’ll break it down for you.

first, you’ll need a phaseCheck function to check which phase you are on

def phaseCheck():
var black = hero.findFlag("black")
var purple = hero.findFlag("violet")
var green = hero.findFlag("green")
if (hero.time < 50) : #use time for the first phase, since the timer starts right away and placing a flag takes time.
phase1() # this is a function, name it however you like
pass
if (black):
move() # this is a function, name it however you like
pass
if(violet)
phase2() # this is a function, name it however you like
pass
if(green)
phase3() # this is a function, name it however you like
pass

make the functions necessary for all oof this to work

Phase1 function starts here

use findByType to find “catapults”, and assign the nearest one to a variable

var friends = hero.findFriends
var catapults = hero.findByType("catapults")

Use a for loop to loop over your friends and assign the friend variable. Then, define a findNearest variable

var catapult = friend.findNearest(catapults) #note: we use a friend variable instead of a hero variable to split the soldiers into two group

for loop start
once you defined your variables, command your soldiers to attack the catapults, command your archer and paladins to defend the hero (self explanatory)

when the catapults die, their last shot will hit your soldiers. command them to get away or break the door (they might live, they might not.)

if (catapult) :
#attack
else
#run away or attack the door

for loop end
Phase 1 function end

once everything is done, move your hero using move function

def move (black):
hero.pickUpFlag(black)

Munchkins will spawn as soon as you take down the door. move back a little and let your archers do the work

You’ve now reached phase two! this phase is the hardest one to beat, since the energy towers have a whopping 2000 hp. place a green flag to begin

Phase 2 start
Find your friends and loop over them. make your paladins focus healing on the hero. yes, just the hero .

# In a for loop
if (friend.type == "paladin")
hero.command(friend, "cast", "heal", hero)
pass

command the archers to do a suicide mission by attacking the towers.
find the towers with findByType(“tower”), and find the nearest one

var towers = hero.findByType("tower")
var tower = hero.findNearest(towers)

depending on what tower the hero aims for, move to the top of the towers, or the bottom. to avoid taking double damage

if (tower && tower.pos.y > 40) : #change the number to the center y pos.
hero.move({x : tower.pos.x, y: tower.pos.y+ 5}) #for the top tower
hero.attack(tower)
pass
else if (tower && tower.pos.y < 40) : #change the number to the center y pos.
hero.move({x : tower.pos.x, y: tower.pos.y - 5}) #for the bottom tower
hero.attack(tower)
pass
else:
var enemy = hero.findNearestEnemy # this is for attacking the door
if enemy
hero.attack(enemy)
pass
pass

while attacking the towers, make sure your paladins constantly heal the hero
once all towers are down, break the second door.
Phase 2 end

remove the green flag after you break the door by placing a black flag.

soldiers will spawn at the other side of the area. wait until the ogres die before proceeding

Phase3 start

once you move next to the door command two warlocks will spawn. iterate over your troops command to attack them

place a purple flag

var warlocks = hero.findByType("warlock")
var warlock = warlocks[0] #works practically the same as findNearest
if (warlock):
#attack them with your troops

once you defeat all the warlocks, collect the gems (use else if)
after collecting all gems, use another else to summon troops and command your troops to attack the door

After that kill all the ogres left and you win

Sorry for the crude explanation, I’m struggling to comprehend how to do the second phase without my magic minions, hope this helps

P.S : yes that oof is intentional

Riley