[Adventurer] The One Wizard

get wrecked. (20 argh.)

1 Like

@Chaboi_3000 why must you do this to me :sob:

I really love this level. It took me quite a while to get all the bonus goals but I finally did it. I was over complicating it in my code so I restarted and it was a breeze. The catapult did catch me off guard the first time but after knowing about it a small addition to my code and no problem.

Hello! This was a fun level to figure out. However, thereā€™s one quirk in my code thatā€™s bothering me. I designated the left button for the Scout unit since my hero otherwise canā€™t defeat it. But then the next time a scout unit appears, my hero insists on running against the left button instead of using other spells, even though the button doesnā€™t work again. How do I fix this so my wizard at least tries to defeat the second scout? I tried moving down the relevant code into the elif chain but it doesnā€™t seem to change things.

By the way, I saw the hero.health bit in this thread but I donā€™t recall learning about it in the first two free campaigns. When does it appear?

My code
while True:
    enemy = hero.findNearestEnemy()
    
    if enemy:
        if hero.canCast("chain-lightning") and hero.distanceTo(enemy) < 30:
            hero.cast("chain-lightning", enemy)
        elif hero.canCast("lightning-bolt"):
            hero.cast("lightning-bolt", enemy)
        elif enemy.type == "scout" or enemy.type == "catapult":
            hero.moveXY(5, 36)
        else:
            hero.attack(enemy)
    elif hero.canCast("regen") and hero.health < 75:
        hero.cast("regen", hero)

create a variable. Call it ā€œtriggeredā€ or something. triggered = False in the beginning. Then, when you use the button, set triggered = True. Then change elif enemy.type == ā€œscoutā€ or enemy.type == ā€œcatapultā€ to elif (enemy.type == ā€œscoutā€ or enemy.type == ā€œcatapultā€) and triggered = False:

1 Like

Thanks! Iā€™ll try it out next time I log into CodeCombat. Itā€™s not something Iā€™ve encountered in the campaign yet, but variables are a basic.

whats the code for that? Mod edit: Please do not request solutions. The purpose of this board is to assist people with their code. Simply providing solutions is counter productive to the learning process. There are many people here willing and able to assist you with your code but we do not just give the answers. Thanks.

Please stop asking for code.

How do you defeat the scouts?

how do you defeat the ogres?

sorry I mean the catapult

Hint: read the hints. :slight_smile:

1 Like

Definitely read the hints!!

This level is very particular about timing to let your powers recharge. I also found it helpful to be selective with my spells and when I cast them. The rest is finding a pattern to the attacks and moving enough to buy some time and regen. Thankfully, it seems that there is only one seed (configuration of enemy attacks) so your run simulations match the submit. It may take some time trying some combinations of spells and movement, but you can complete all goals.
One%20Wizard%20success

2 Likes

I definitely agree with what @brooksy125 and @Chaboi_3000 said here. Your solution is going to involve a bit of moving about and juking a little. One thing that helped me out was setting my hero to patrol around a bit. :slight_smile:

1 Like

Bumping because I am having some troubles. Took a few days break and I canā€™t get seem to get any of my codes to work. Presently, the block of code I have is coming back ā€˜Nullā€™ and I am not sure why. I have the variable ā€˜enemyā€™ set up, so I would think there would be no problem:

while(true) {
     var enemy = hero.findNearestEnemy();
      if (enemy.type == "ogre") {
          hero.moveXY(5, 40);
      } else if (enemy.type == "munckin") {
          hero.attack(enemy);
      }
}

Thanks for the feedback.

Hi bobmcphe!
In case no enemy has been found, however, you canā€™t possibly check ā€œtypeā€ of ā€œundefined/nullā€ (enemy)
best to check, if thereā€™s an enemy first (you can have multiple conditions!)
example:

if (enemy && enemy.type == "ogre"){ // NOT (enemy.type == "ogre" &&  enemy)
    doSomething();                  //       the order is important!
}

You could also put the if & else if block inside another if block that checks for existence of the enemy.

That would be the only problem i could see happening.

2 Likes

I see, so the logic would be: IF - enemy - IF - enemy.type. Thank you.

Ok, so, I updated my code, and now there is no syntax or run-time error, but Hushbaum just stands there and does nothing. Updated code below:


while(true) {
     var enemy = hero.findNearestEnemy();
      if (enemy && enemy.type == "ogre") {
          hero.moveXY(5, 40);
      } else if (enemy && enemy.type == "munckin") {
          hero.attack(enemy);
      }

oh, itā€™s ā€œmunchkinā€ not ā€œmunckinā€! Didnā€™t see that.

Dangā€¦seems like no matter how many times I look, I always miss something like thatā€¦Thanks again.