Raiders of the long dark


#1

how to use hero.command(peasant,“buildXY”, peasant.pos) ,it can not work


#2

You’re doing it wrong. It needs an X and Y. Do hero.command(peasant,"buildXY","[Build type],X,Y


#3

example: hero.command(peasant,“buildXY”,“palisade”,17,35) Is it right?


#4

Yeah, I think that’ll work


#5

arryn = hero.findByType(“raider”)[0]
peasant = hero.findByType(“peasant”)[0]

def chooseHeroStrategy():
# Return either “fight” or “advance”.
# Try to stay 5m behind the peasant when not fighting.
# Don’t get more than 15m away from the peasant.
enemy = hero.findNearestEnemy()
if enemy:
if hero.distanceTo(peasant) > 15:
return “advance”
return “fight”
else:
return “advance”
pass

def heroFight():
# Stop the ogres from rushing past you to get to the peasant!
# Hint: try to slow them down if you can
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
pass

def heroAdvance():
# Stay behind the peasant
hero.moveXY(peasant.pos.x - 5, peasant.pos.y)
pass

def choosePeasantStrategy():
# Return “follow”, “build-above”, or “build-below”
# Hint: use isPathClear() to determine where the hallways are
if hero.isPathClear(peasant.pos, {“x”:peasant.pos.x,“y”:peasant.pos.y + 10}):
return “build-above”
elif hero.isPathClear(peasant.pos, {“x”:peasant.pos.x,“y”:peasant.pos.y - 10}):
return “build-below”
else:
return “follow”
pass

def peasantAdvance():
# Keep the peasant behind Arryn and her soldiers.
hero.command(peasant, “move”, {“x”:arryn.pos.x -5, “y”:arryn.pos.y})
pass

def peasantBuild(x,y):
# Command the peasant to build a palisade.
hero.command(peasant, “buildXY”, “palisade”, x, y)
pass

while True:

heroStrategy = chooseHeroStrategy()
if heroStrategy == "fight":
    heroFight()
elif heroStrategy == "advance":
    heroAdvance()

peasantStrategy = choosePeasantStrategy()
if peasantStrategy == "build-above":
    peasantBuild(peasant.pos.x, peasant.pos.y + 5)
elif peasantStrategy == "build-below":
    peasantBuild(peasant.pos.x, peasant.pos.y - 5)
elif peasantStrategy == "follow":
    peasantAdvance()

it can not work. why? help me.


#6

Please learn to post your code correctly. The way it is now, we can’t see the structure. Help us help you. It’s very easy to do and just takes a tiny bit of effort. Please read this topic and format your code again correctly