不管如何农民都不会去建造decoy的,下面是我的代码:
def findBestItem(friend, excludeItems):
items = friend.findItems()
bestItem = None
bestItemValue = 0
for item in items:
if item in excludeItems:
continue
distance=friend.distanceTo(item)
rating=item.value/distance
if rating > bestItemValue:
bestItem=item
bestItemValue=rating
return bestItem
loop:
peasants = self.findByType("peasant",self.findFriends())
claimedItems = []
for peasant in peasants:
nearest = peasant.findNearest(peasant.findEnemies())
if nearest:
distance2=peasant.distanceTo(nearest)
if nearest.target == peasant and distance2 <= 10:
if peasant.gold >= peasant.costOf("decoy"):
self.command(peasant, "buildXY", "decoy",peasant.pos.x-2,peasant.pos.y)
coin=findBestItem(peasant,claimedItems)
if coin:
claimedItems.append(coin)
self.command(peasant, "move", coin.pos)
即便把距离改成15,也一样是不会去建造,我认为这是一个bug