The Coding on Thunderhooves

I do not understand why the code works on all yaks except the last one in which my hero panics, and build multiple fences completely blocking his goal.

yak = self.findNearestEnemy()
if yak:
# A yak is above you if it’s y is greater than your y.
# If the yak is above you, build a fence 10m below it.
x = self.pos.x
y = self.pos.y
self.buildXY(“fence”, x, y)
# Move right 10m towards the oasis.
x = self.pos.x + 10
y = self.pos.y
self.moveXY(x, y)

if yak:
        if yak.pos.y > self.pos.y:
            self.buildXY("fence", self.pos.x, yak.pos.y-10)

As already mentioned by Vlevo in another post, please use 3 backticks (```) before and after your code to display it properly. This is also written in the FAQ, which you should have read anyway before posting.

Quotes (>) are there for quoting. Please do not use them to display code, as they won’t color it at all. We have designated code-blocks for a reason.

Also the snippet you gave is not very useful without an explanation.

What you do is not what is your task. The comment asks you to build a fence 10m below the position of the yak (yak.pos.y-10), but you build it exactly at your position. I wonder that you actually got to the last Yak without problems.

Sorry, I cannot paste my code the proper way like you guys do. Tharin is yet unexplainably scared of a yak.

See FAQ:




1 Like