Has anyone figured out to pick only the Nearest Gold Coins?


#1

I know how to pick the gold coins and how to pick the nearest coins, but was wondering, how could I make an array of gold coins and pick the nearest of these? Is it possible?


#2

Y U NO HAVE CODE


#3
  1. Step 1: get an array of coins and learn how to get their properties
items=this.findItems();
for(i=0;i<items.length;i++)
    this.say("look! another coin of value "+ item.value+" at location "+item.pos);
  1. Step2: select only the gold coins and put them into another array (gold is coin.value==3)

  2. Step3: find the nearest item in the second array

Or much simpler, replace the this.say in the code above with the standard algorithm for find the best property:

best_id =  null
min_property = Infinity
for( all items in the list)
     //In the for code above, replace the say with this test
     if( property(item) < min_property)
            min_property = property(item)
            best_id =item



#4

Second option:

This makes an array of gold coins:

gold = [coin for coin in self.findItems() if item.value is 3]

It loops through all the items in and if the value property is 3 adds it to a new array called gold.


#5

Why does this not work?

coins = []
for item in hero.findItems():
    if item.value == 3:
        coins.append(item)
coin = hero.findNearest(coins)
hero.move(coin.pos)