So I thought I was making progress but now I’m feeling defeated
I got my peasants to get gold based on distance and value, and tried to make them ignore each others targets, but they still go after each others gold.
I made a function called pickTarget(friend) the plan was to return a warlock if present or closest enemy if not.
I wanted paladins and griffin-riders to be able to use it == fail
the last thing that I’m stuck on is I can’t seem to make the paladins heal the weakest. They were at one point but not now. I don’t know what changed.
Any help would be great.
on a side note I really like CodeCombat, but sometimes really with I had a debugger, or at least a log of what happened
# 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 #self.say("mosthurt "+lowestFriend) 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") mostHurt=lowestHealthPaladin() if mostHurt and mostHurt.health<400 and paladin.canCast("heal"): #self.say(paladin +" can heal "+mostHurt) self.command(paladin, "cast", "heal", mostHurt) if paladin.health < 99: self.command(paladin, "shield") else: target=pickTarget(paladin) if target: self.command(paladin, "attack", target) def pickTarget(friend): warlocks=self.findByType("warlock") nearEnemy=friend.findNearest(friend.findEnemies()) targetWarlock=friend.findNearest(warlocks) if targetWarlock: return targetWarlock else: if nearEnemy: return nearEnemy def commandFriends(): # Command your friends. friends = self.findFriends() for friend in friends: if friend.type == "peasant": self.command(friend, "move", targetGold(friend).pos) elif friend.type == "griffin-rider": target=pickTarget(friend) if target: self.command(friend, "attack", target) elif friend.type == "paladin": commandPaladin(friend) def targetGold(friend): items=friend.findItems() if items: peasants=self.findByType("peasant") activeMoneyTarget= for peasant in peasants: highValue=-1 if not item in activeMoneyTarget: for item in items: distanceToItemValue=(item.value/friend.distanceTo(item)) if distanceToItemValue>highValue: target=item highValue=distanceToItemValue activeMoneyTarget.append(target) return target def summonGriffins(): if self.costOf("griffin-rider")<self.gold: self.summon("griffin-rider") loop: commandFriends() summonGriffins()