Hi, guys!
I have troubles with Grim Determination level.
What are the main ideas for building right strategy?
My current 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
paladinPoint = {'x': 88, 'y': 43}
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")
lowestFriend = lowestHealthPaladin()
healingThreshold = 0.8 * paladin.maxHealth
warlocks = self.findByType('warlock')
nearestWarlock = paladin.findNearest(warlocks)
nearestEnemy = paladin.findNearest(self.findEnemies())
# if nearestWarlock:
# dx = nearestWarlock.pos.x - paladin.pos.x
# dy = nearestWarlock.pos.y - paladin.pos.y
# dist = dx**2 + dy**2
if lowestFriend and paladin.canCast('heal') and lowestFriend.health < healingThreshold:
self.command(paladin, 'cast', 'heal', lowestFriend)
elif nearestWarlock:
self.command(paladin, 'attack', nearestWarlock)
elif nearestEnemy:
self.command(paladin, 'attack', nearestEnemy)
else:
self.command(paladin, 'defend', paladinPoint)
def commandGriffin(griffin):
warlocks = self.findByType('warlock')
nearestWarlock = griffin.findNearest(warlocks)
nearestEnemy = griffin.findNearest(self.findEnemies())
if nearestWarlock:
self.command(griffin, 'attack', nearestWarlock)
elif nearestEnemy:
self.command(griffin, 'attack', nearestEnemy)
else:
self.command(griffin, 'defend', paladinPoint)
def commandPeasant(peasant):
peasants = self.findByType('peasant')
for i, pes in enumerate(peasants):
if pes is peasant:
break
coins = self.findItems()
nearestCoin = peasant.findNearest(coins)
if i == 0 and nearestCoin.pos.y <= 43:
self.command(peasant, 'move', nearestCoin.pos)
elif i == 1 and nearestCoin.pos.y > 43:
self.command(peasant, 'move', nearestCoin.pos)
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 summonGriffin():
if self.gold >= self.costOf('griffin-rider'):
self.summon('griffin-rider')
loop:
commandFriends()
# Summon griffin riders!
summonGriffin()