Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Interception HELP (SoLvEd)


#1

Hello, I was going back to extra levels that i never passed and I was wondering if anyone can help me with my problem.

Here’s my code:

while True:
    enemy = hero.findNearestEnemy()
    friend = hero.findNearestFriend()
    # Calculate x by adding friend.pos.x to enemy.pos.x
    # Then divide by 2.
    # Check the guide if you need more help!
    x = (friend.pos.x + enemy.pos.x) / 2
    # Now do the same for y
    y = (friend.pos.y + enemy.pos.y) / 2
    # Move to the x and y coordinates you calculated.
    x = ("tower".pos.x + peasant.pos.x) / 2
    y = ("tower".pos.y + peasant.pos.y) / 2

Here’s a screenshot:


#2

You’re pretty close. You define x and y twice. The first definitions are unnecessary, the second are close but tower is not a string and you shouldn’t be using peasant in the equation, you have defined friend above so use it there. Also, you never tell your hero to move to the x and y coordinates defined as x and y.


#3

I’m not sure what im supposed to fix next :sweat_smile:
can you help me please?


#4

You’re adding the hero’s coordinates to your friend’s. You’re supposed to add the enemy’s coordinates to your friend’s. Then after defining x and y, you call moveXY() and move to the defined x and y coordinates.


#5

yayyyyyy i got it, thank youuu!!! :grin::stuck_out_tongue_closed_eyes: