迷雾岛矿藏这关有人通过了吗?
codecombat吧
全部回复
仅看楼主
level 1
紫雨蝶眸 楼主
为啥不管怎么样农民都无法建造一个陷阱?
2016年08月02日 07点08分 1
level 1
紫雨蝶眸 楼主
怎么没人!!!
2016年08月02日 09点08分 2
level 1
command(peasant, "buildXY", "decoy", {'x':peasant.pos.x-2,'y':peasant.pos.y})
2016年08月02日 13点08分 3
然后就是那个nearest.target是不是必须要有火蛋白灵石才行,你的建造条件(if)是怎么写的,可否分享一下?
2016年08月03日 07点08分
level 1
紫雨蝶眸 楼主
还是不行的,就算是按照这个来做,这些农民根本就不会去建造decoy的
2016年08月03日 08点08分 4
level 1
紫雨蝶眸 楼主
@易卜拉欣102 ,我的代码如下:
def findBestItem(friend, excludeItems):
items = friend.findItems()
bestItem = None
bestItemValue = 0
for item in items:
if item in excludeItems:
# Another peasant is already targeting this item
# The continue statement skips to the beginning of the next iteration of the for-loop
continue
# Find the best item: value divided by distance
distance=friend.distanceTo(item)
rating=item.value/distance
if rating > bestItemValue:
bestItem=item
bestItemValue=rating
# Make sure to return the bestItem!
return bestItem
loop:
peasants = self.findByType("peasant")
claimedItems = []
for peasant in peasants:
nearest = peasant.findNearest(peasant.findEnemies())
# Peasants have gold and costOf() properties, and obey the "buildXY" command.
# If there's an enemy within 10 meters targeting this peasant, build a "decoy" if we can afford one.
# You can get the enemy's target with nearest.target
# Otherwise, use findBestItem to target the best coin to collect
# Use claimedItems.append(item) to add it to the claimedItems array.
if nearest:
distance2=peasant.distanceTo(nearest)
if nearest.target == peasant:
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)
2016年08月03日 08点08分 5
level 1
紫雨蝶眸 楼主
感觉这个代码没有任何问题了,但是就是不会建造,条件里面加了distance 〈= 10或者15都是不行的,都不会建造
2016年08月03日 08点08分 6
1