Underground Business-Help!


#1

Can’t move to the X point…


#2

What I think is wrong with your code is that there is always skeletons near your hero and attacking them just ignore the moveXY code.

I believe if you replace your if enemy with:

if enemy and hero.gold < 300:

it should fix the problem


#3

Tried before ,didn’t work…


#4

I checked the answers of other players in the scoring board and sometimes your code will work but not always.
I guaranteed the success by putting “if hero.gold >= 300” as the first condition and all other conditions as sub conditions with “elif” and “else”. I think the mimic or the hero must collect the gems from the peasants, so I made the hero oscillate ( with move not moveXY) between the enemies and the gems.


checked the gold before going to exit:

pet.debug("hero's gold is " + hero.gold) 

( anybody has access to pet.debug without advanced books)


#5

You normally won’t get the gold if the mimic moves directly to the hero’s position. You have to make the mimic move 3 meters up of the hero like this: pet.moveXY(hero.pos.x, hero.pos.y + 3).


#6

ah I had trouble with this too but I figured it out.


#7

Finally I used flag… but I don’t think it’s the best solution…


#8

If you have finished the level and are in the search of better solution click “Scores” , choose one of the tabs on the left and click on “Watch”. You can find tons of clever thinking in every level.


#9

I didn’t use flag for this.


#10

yeah just look at the scores.


#11

Can someone who has finished the level explain what is going on in the code of Hazow ( Top Players by Gold Collected, All-Time)

var isOver = false;

function onSpawn(event) {
    //  moving pet
    isOver = true;
}
pet.on("spawn", onSpawn);

while (!isOver) {
    // fighting
}
while(true){
     // collecting excess gold and going home 
}

How can this structure be exploited and is it faster and more efficient than conventional resolutions?


#12

I would help but I don’t do java.


#13

sorry
(20 characters is really getting annoying)


#14

Yeah 20 characters are really annoying.

I think he/she did that so that no one could could copy their coding. A lot of people changed their code to comments or erased their code so that no one could copy it.


#15

@Seojin_Roy_Lee The code of Hazow is still intact - little modification so it cannot be copy&pasted:

var isOver = false;

function onSpawn(event) {
    // go to the corners
    pet.moveXY(hero.pos.x, hero.pos.y);
    isOver = true;}

pet.on("spawn", onSpawn);

while (!isOver) {
    var enemy = hero.findNearestEnemy();
    if(enemy){
        while (enemy.health > 0) {
            hero.attack(enemy);}}
    hero.moveXY(20, 34);}

while(true){
    var coin = hero.findNearestItem();
    if(!coin){ break;}
    hero.move(coin.pos);}
hero.moveXY(50, 34);

@Gamestack in this case simply remove braces and change a little bit the indentation and you have python from JS


#16

Cool. Thx. I’ll check that.