If you want a neaster friend of the same type, it returns itself


peasants = self.findByType('peasant')
for peasant in peasants:
    if peasant.type == 'peasant':
        other_peasant = peasant.findNearest(peasants)
        #other_peasant = peasant.findNearest(self.findByType('peasant'))#Fail too
        self.say([peasant,other_peasant ])


I don’t know if it is intentional or not, but the behavior of findNearest makes sense to me, as the peasant is closest to itself.

If you want to find the other peasant nearest to that peasant you will have to filter out the original peasant. Not exactly sure how to do that in Python, but I can imagine it looks like this:

peasants = self.findByType('peasant')
for peasant in peasants:
    other_peasants = []
    for p in peasants:
        if p.id == peasant.id:
    other_peasant = peasant.findNearest(other_peasants)
    self.say([peasant, other_peasant])

(In JavaScript I cheat and do this:)

// in a loop...
var otherPeasants = peasants.filter(function (p) { return p.id !== peasant.id; });
// ...

I second, I don’t think it’s a bug.

Thanks trying to help, I had resolved, just I wanted to mention
if someone else did not match him in his head

points of view…
of course the nearest unit to itself ,is itself yes?, no?,

I think when you’re in a place are “in” , itself != nearest.

In a hypothetical game
if you want to attack the nearest unit, I do not think anyone can think of attacking itself in a game.

know it’s not a “bug”, but found a “nice to have” section.
can you tell me where should have written this?
It is the first time i use the forum