Oh, well, you have to command your peasants to collect coins so that you can summon a griffin-rider in the first place, right?
i have griffins summoned already. But they dont do anything
so i fixed the griffin problem, but when my peasants get gold, they just hide in the cornerâŚ
Can you show us your function for commanding your peasants to collect coins?
Your goal is to protect Reynaldo
Find the paladin with the lowest health.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = self.findFriends()
for friend in friends:
if friend.type != âpaladinâ:
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast(âhealâ) and command(paladin, âcastâ, âhealâ, target)
# Paladins can also shield: command(paladin, âshieldâ)
# And donât forget, they can attack, too!
if paladin:
lowPaladin = lowestHealthPaladin()
if lowPaladin:
if paladin.canCast(âhealâ):
self.command(paladin, âcastâ, âhealâ, lowPaladin)
else:
self.command(paladin, âshieldâ)
def commandFriends():
# Command your friends.
friends = self.findFriends()
for friend in friends:
if friend.type == âpeasantâ:
commandPeasant(friend)
elif friend.type == âgriffin-riderâ:
commandGriffin(friend)
elif friend.type == âpaladinâ:
commandPaladin(friend)
def commandGriffin(griffin):
enemy = griffin.findNearest(griffin.findEnemies())
if enemy:
self.command(griffin, âattackâ, enemy)
def commandPeasant(peasant):
item = peasant.findNearest(peasant.findItems())
self.command(peasant, âmoveâ, item.pos)
loop:
commandFriends()
# Summon griffin riders!
if self.gold >= self.costOf(âgriffin-riderâ):
self.summon(âgriffin-riderâ)
please can you help .i donât hold back the enemy enough. my paladinâs heal and all but donât succeed. same with griffins
Your paladins are not attacking. If they are not healing they should attack, not shield.
You can make them shield when they are very low on health if you really want.
Thanks iâll try it and the branches idea confused me and the code didnât work at all.
def lowestHealthPaladin():
lowestHealth = 99999
lowestFriend = None
friends = self.findFriends()
for friend in friends:
if friend.type != âpaladinâ:
continue
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast(âhealâ) and command(paladin, âcastâ, âhealâ, target)
# Paladins can also shield: command(paladin, âshieldâ)
# And donât forget, they can attack, too!
if paladin:
lowPaladin = lowestHealthPaladin()
if lowPaladin:
paladin.canCast(âhealâ)
self.command(paladin, âcastâ, âhealâ, lowPaladin)
else:
enemy2 = paladin.findNearest(paladin.findEnemies())
if enemy2:
self.command(paladin, âattackâ, enemy2)
def commandFriends():
# Command your friends.
friends = self.findFriends()
for friend in friends:
if friend.type == âpeasantâ:
commandPeasant(friend)
elif friend.type == âgriffin-riderâ:
commandGriffin(friend)
elif friend.type == âpaladinâ:
commandPaladin(friend)
def commandGriffin(griffin):
enemy1 = griffin.findNearest(griffin.findEnemies())
if enemy1:
self.command(griffin, âattackâ, enemy1)
def commandPeasant(peasant):
item = peasant.findNearest(peasant.findItems())
self.command(peasant, âmoveâ, item.pos)
loop:
commandFriends()
# Summon griffin riders!
if self.gold >= self.costOf(âgriffin-riderâ):
self.summon(âgriffin-riderâ)
indent preformatted text by 4 spaces
I tried the code and it didnât work.
Format the code by surrounding by 3 back-quotes (to left on your keyboard):
code here
-
Do not use so many branched ifs. In
commandPaladin
add a return after eachself.command
instruction.
In this way you do not need to guard your instructions by an else -
paladin.canCast('heal")
returns a true/false expression: you must test this expression in an if just like you have done forisReady("cleave")
:
def commandPaladin(paladin):
# Heal the paladin with the lowest health using lowestHealthPaladin()
# You can use paladin.canCast("heal") and command(paladin, "cast", "heal", target)
# Paladins can also shield: command(paladin, "shield")
# And don't forget, they can attack, too!
if not paladin:
return
lowPaladin = lowestHealthPaladin()
if lowPaladin:
if paladin.canCast("heal"):
self.command(paladin, "cast", "heal", lowPaladin)
return
enemy2 = paladin.findNearest(paladin.findEnemies())
if enemy2:
self.command(paladin, "attack", enemy2)
return
# you can add code for shield or move here
# if (condition to shield)
# shield
# return
Thank you, i did it!