Hi again guys, i was curious to see if it’s possible to calculate the ratio of distance/worth of an item.
How would you write it?
I tried writing my own, but don’t know if it’s really working,
because my hero looks very indecisive while he’s running from coin to coin
(by that i mean that he keeps on turning and it seems like he’s running slower than he should)
so this is my code, I based it on the model of finding the closest coin not using the findNearest function
this.pickUpCoin = function(){
items = this.findItems();
maxRatio = 0;
for(i=0;i<items.length;i++){
item = items[i];
ratio = item.value/this.distanceTo(item);
if (ratio>maxRatio) maxRatio = ratio;
items[i].ratio = ratio;
}
for(i=0;i<items.length;i++){
if (items[i].ratio>=maxRatio){
this.move(items[i].pos);
}
}
};
thanks a bunch!