Hello,
I’m new and this is my first post. Hope I don’t mess up…
My Code
# 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)
if paladin.canCast("heal") and lowestHealthPaladin():
self.command(paladin, "cast", "heal", lowestHealthPaladin())
# Paladins can also shield: command(paladin, "shield")
else:
self.command(paladin, "shield")
def commandPeasant(peasant, value):
# collect coins of certain values
coins = self.findItems()
gems = []
for c in coins:
if c.value > value:
gems.append(c)
gem = self.findNearest(gems)
if gem:
self.command(peasant, "move", gem.pos)
def commandGriffin(griffin):
# attack the enemy
enemies = self.findEnemies()
if enemies != []:
continue
if griffin:
self.command(griffin, "attack", griffin.finedNearest(enemies))
def commandFriends():
# Command your friends.
friends = self.findFriends()
for friendIndex, friend in enumerate(friends):
if friend.type == "peasant":
commandPeasant(friend, friendIndex)
elif friend.type == "griffin-rider":
commandGriffin(friend)
elif friend.type == "paladin":
commandPaladin(friend)
# ---
# SETUP
# global variables
# check
self.say(lowestHealthPaladin()) # problem: NOTHING HapPENS!
self.say(self.findByType("paladin")) # ? not even NULL
self.say("hi!") # to keep it simple... but no, nothing
# move Paladins forward
for friend in self.findByType("paladin"):
newX= friend.pos.x + 10
self.command(friend, "move", {"x":newX ,"y":friend.pos.y})
# LOOP
loop:
if self.now() > 2: # to make sure they can move forward in setup
commandFriends()
if self.gold >= self.costOf("griffin-rider"):
self.summon("griffin-rider")
I’m especially baffled by the fact that my hero says nothing on a beginning statement…
self.say("hi!")
Well, and nothing else of the code works. It might be that the code does not beat the level, but I haven’t been able to test even a simple version, just to see if I understand how Paladin-casting works…
I reloaded the game several times, so that’s not it, I guess. I’m working in Chrome.
I feel kinda stupid.
Any ideas?