Goalkeeper Level Help (JS) - How to Get The Bonus

Hello guys. I have recently attempted the Goalkeeper level, and after some time, I managed to succeed the level. However, I can’t seem to get the bonus.

var friends = hero.findFriends();
while(true) {
    for (var friendIndex = 0; friendIndex < friends.length; ++friendIndex) {
        var friend = friends[friendIndex];
        var ball = hero.findNearest(hero.findByType("ball"));
        hero.command(friend, "move", {"x": 15, "y": ball.pos.y});
        if (ball.pos.y > friend.pos.y) {
            hero.command(friend, "move", {"x": 15, "y": ball.pos.y+1});
        } else {
            hero.command(friend, "move", {"x": 15, "y": ball.pos.y-1});
For those who use Python
friends = hero.findFriends()
while True:
    for friend in friends:
        friend = friends[friendIndex]
        ball = hero.findNearest(hero.findByType("ball"))
        hero.command(friend, "move", {"x": 15, "y": ball.pos.y})
        if ball.pos.y > friend.pos.y:
            hero.command(friend, "move", {"x": 15, "y": ball.pos.y+1})
            hero.command(friend, "move", {"x": 15, "y": ball.pos.y-1})

I will be able to accept help in either JavaScript of Python

Could any of you help?


this is prob about RNG or flag placment so try doin that

ALSO TRY usin flags it makes things easy

Personally, I prefer to write autonomous code than rely on flags.

As your goal is to only play defensively, the easiest way to block the ball from passing is to move your peasants to the same y position as the ball, as you’ve done. Ideally your peasants would efficiently guard the entire x=15 line, but they aren’t fast enough to always keep up with the ball when simply trying to match its position. Your goal is to efficiently guard the x=15 as well as possible with your slower peasants.

  1. It only takes one peasant to block the ball, leaving the other free. Are you able to move to the other part of the x=15 line just in case the ball suddenly flies that way?

  2. Your peasants “lag” behind the ball position, can you use the ball’s velocity to better intercept it?

My solution was 9 lines of clean JS, so don’t try to complicate your code with convoluted methodology.

If you would like more specifics, feel free to ask.

or just random luck XD(sry that was a joke) i normaly use 1 peasant to kick and 2 to defend in the back
(my defence is the girls since im a boy but that does not mater)