Magic exam, cant fully complete

Code is below, it works fine, I just don’t know what to do with the poison bottle. I thought you should just ignore it, but I don’t get the last coin from not collecting it. Do I attack the potion or something?

def regenAlly(ally):
    self.cast("regen", ally)
def healAlly(ally):
    self.cast("heal", ally)

def growAlly(ally):
    self.cast("grow", ally)

def attackEnemy(enemy):
    self.cast("drain-life", enemy)

def shrinkEnemy(enemy):
    self.cast("shrink", enemy)

def takeItem(item):
    hero.moveXY(item.pos.x, item.pos.y)

def poisonOgre(enemy):
    self.cast("force-bolt", enemy)

def cloudEnemy(enemy):
    self.cast("poison-cloud", enemy)

while True:
    hero.moveXY(18, 40)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(18,24)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(34,40)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(34,24)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        if ally.type == "zana":
            hero.say(zana)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(50,40)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(50,24)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(66,40)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(66,24)
    enemy = hero.findNearestEnemy()
    ally = hero.findNearestFriend()
    item = hero.findNearestItem()
    if item:
        if item.type == "potion":
            hero.moveXY(item.pos.x, item.pos.y)
        if item.type == "poison":
            poisonOgre(item)
    if ally:
        if ally.type == "soldier":
            healAlly(ally)
        if ally.type == "goliath":
            growAlly(ally)
        else:
            if ally.type != "soldier" and "goliath":
                regenAlly(ally)
    if enemy:
        if enemy.type == "brawler":
            shrinkEnemy(enemy)
        if enemy.type == "ogre":
            poisonOgre(enemy)
        if enemy.type =="scout":
            cloudEnemy(enemy)
        else:
            hero.say(enemy.type)
    hero.moveXY(78, 33)
    break

4 Likes

Cast grow to yourself, and take it. He will then say I see you are a scientist, continue with your experiments giving you the coin

2 Likes

oh, thanks, I would never have thought that.

I hope this is not considerd giving you the solution, but its a bit af an annoying one

Hello and welcome to codecombat discourse! This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

So I used some for-loops(you will understand that in the mountains) to get all of the bonuses.

1 Like

Hey @Memedealer2111 welcome to the forum! I’m going to leave this level to the others however I do want to remind you to give the solution to whoever helps you the most aka gives you the right way to fix your code. Thanks!

@milton.jinich please refrain from posting solutions. I know you are just showing a way of doing it but it is still considered a solution according to the guidelines.

uhh i dont think he posted a solution just a small hint to complete the level also he doesnt understand for loops yet so yea

1 Like

and i think you mean QinWentian

He posted a whole paragraph of code…

Who are you talking about Milton or Meme

Sorry Am I the one posting the wrong thing, Ill take it down if need be

Give a sulution (the check mark in the corner) to the person who helped you most

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.