I’ve been trying this level for a while, and I’m not sure how to do it. I’ve tried checking other posts, but most of them are in Python, so I can barely understand it. (Yes, I’m aware the two languages are really similar) Here’s my code:
while(true) {
var blueskelly = hero.findEnemies();
var ball = hero.findByType("ball")[0];
var peasant = hero.findByType("peasant")[0];
for (var i = 0; i < blueskelly.length; i++) {
if (ball.velocity.magnitude() == 0) {
var blue = blueskelly[i];
var goal = Vector.subtract(blue.pos, ball.pos);
goal = Vector.normalize(goal);
goal = Vector.multiply(goal, -7.51);
goal = Vector.add(goal, ball.pos);
hero.command(peasant, "move", goal);
hero.wait(1.5);
hero.command(peasant, "move", ball.pos);
hero.wait(0.8);
hero.command(peasant, "move", goal);
hero.wait(2);
}
}
}
Never mind, you can see my new code above, I think I got it, thanks to an older forum post, but sometimes my peasant runs into the ball. Any way to fix it?
This is a tricky level, you’d need three components:
One that finds an optimal starting point. This can be done by getting a vector from the skeleton to the center, and then adding a fixed magnitude of that vector to the center point to get the point opposite to the target skeleton.
Then you’d need to design a collision avoidance system that gets to the starting point without touching the ball. I first got a vector from the ball peasant, and then used a magnitude of n/distanceToBall^2 such that the closer the peasant gets, the stronger the “push” away from the ball gets. You can then add that vector to your starting point vector to “dodge” the ball.
Once you find that the peasant location is at the starting point, you can have the peasant “kick the ball”, which would already be towards the correct skeleton since you figured out the location in step 1. I would suggest having the peasant move to a close corner right after kicking so that it doesn’t hit the ball when it respawns.
It’s a hard level, and I admit I used flags to brute-force the level when I first solved it. (Back when Nalfar was locked behind the level in 2017) With a bit more knowledge now though I was able to combine the top three into something like: