[SOLVED]Crossroads

i have the gist of it down like I destroy most of the ogres but my code will not kill some of them can you help me please?

# Only build if you see an enemy.

# The function defines THREE parameters.
def maybeBuildSomething(buildType, x, y):
    # Move to the position specified by x and y parameters.
    hero.moveXY(x, y)
    # Find the nearest enemy.
    enemy = hero.findNearestEnemy()
    # If there is an enemy
    if enemy:
        # then use buildXY with buildType, x, and y
        hero.buildXY("fire-trap", 40, 22)
        hero.buildXY("fence", 26, 35)
        hero.buildXY("fire-trap", 40, 50)
        hero.buildXY("fence", 54, 35)
    pass
    
while True:
    # Call maybeBuildSomething with "fire-trap" and the coordinates of the bottom X.
    hero.buildXY("fire-trap", 55, 34)
    # Call maybeBuildSomething, with "fence" at the left X!
    hero.buildXY("fire-trap", 25, 34)
    # Call maybeBuildSomething with "fire-trap" at the top X!
    hero.buildXY("fire-trap", 40, 49)
    # Call maybeBuildSomething with "fence" at the right X!
    hero.buildXY("fire-trap", 40, 19)

You are almost there you just need to do something like this

elif enemy.pos.x > hero.pos.x:
            # buildXY a "fire-trap" on the right X.
            hero.buildXY("fire-trap", 55, 34)

This level is randomized so it won’t be useful to hard code it.

ok i got it thanksyou

Do you understand now.

yea i understand it now

So do you still need help now or is this solved.

solved for now it is being anoying i am just waiting for that good seed

Okay you still need help since it works for me every time and I did it with a free hero with 4speed. Post your recent code and I can help you.

this is my recent code

# Only build if you see an enemy.

# The function defines THREE parameters.
def maybeBuildSomething(buildType, x, y):
    # Move to the position specified by x and y parameters.
    hero.moveXY(x, y)
    # Find the nearest enemy.
    enemy = hero.findNearestEnemy()
    # If there is an enemy
    if enemy:
        # then use buildXY with buildType, x, and y
        hero.buildXY("fire-trap", 40, 22)
        hero.buildXY("fence", 26, 35)
        hero.buildXY("fire-trap", 40, 50)
        hero.buildXY("fence", 54, 35)
    pass
    
while True:
    # Call maybeBuildSomething with "fire-trap" and the coordinates of the bottom X.
    
    hero.buildXY("fire-trap", 51, 34)
    hero.buildXY("fire-trap", 51, 37)
    hero.buildXY("fire-trap", 51, 31)
    # Call maybeBuildSomething, with "fence" at the left X!
    hero.buildXY("fire-trap", 40, 19)
    hero.buildXY("fire-trap", 43, 19)
    hero.buildXY("fire-trap", 36, 19)
    # Call maybeBuildSomething with "fire-trap" at the top X!
    
    hero.buildXY("fire-trap", 25, 34)
    hero.buildXY("fire-trap", 25, 31)
    hero.buildXY("fire-trap", 25, 38)
    # Call maybeBuildSomething with "fence" at the right X!
    hero.buildXY("fire-trap", 40, 40)
    hero.buildXY("fire-trap", 43, 40)
    hero.buildXY("fire-trap", 37, 40)

Okay I think you need to restart so I can take you through step by step.

i keep getting it when i am not in submit mode but when i submit i cant get it

i finally got it i relized that the guy in the top comes first when you submit

I know because there is a random seed and it changes every time. Please I will take you step by step and eplain it. So do this if enemy.pos.x < hero.pos.x: # buildXY a "fire-trap" on the left X. hero.buildXY("fire-trap", 25, 34)

This will tell your hero move left if the enemy.pos.x is less than your heroes.

umm i completed the level

and i figured it out

Okay great mark whichever post helped you solve our problem and congrats on completing this level.

umm none of the posts helped me tbh i just observed the patters in the submit functiin

then mark any post as solved so that this can be closed since you solved it

For example your own post, @logan_jordan .

1 Like