My plan is the following:
First I get all items and save them in items
. Then I sort them by their distance to me and approach the next one.
The actual code is a bit more complicated (I don’t check all coins on the field), but for my idea to work I need to sort a given coin-array by distance. According to this thread I can’t use a lambda-function, so I try to create one outside and use it like the following:
self.func(n) = function(n) return self.distance(n)
items = self.getItems()
items.sort(key=func)
Now I expect items to be sorted in ascending order by distance. I can now grab the first element and move to it:
self.move(items[0].pos)