Hi everyone,
I’ve recently found that a lot of my Multiplayer Treasure Grove matches end in ties. At first I thought it was my code, but closer inspection revealed that in every case it was just their hero with an error, and my hero not doing anything:
Another strange thing is that I only get the ties when fighting against red players, and the enemy hero always seems to be Tharin or Anya.
Here is my code in case there is a bug in it, in which case apologies for the disturbance:
def findBestItem(items):
bestItem = None
bestValue = 0
itemsIndex = 0
while itemsIndex < len(items):
item = items[itemsIndex]
if item.value / hero.distanceTo(item) > bestValue:
bestItem = item
bestValue = item.value / hero.distanceTo(item)
itemsIndex += 1
return bestItem
def summonArmy(target):
if hero.canCast("summon-burl", target):
hero.cast("summon-burl")
if hero.canCast("summon-undead", target):
hero.cast("summon-undead")
def findBestCorpse(corpses):
bestCorpse = None
bestValue = 0
corpsesIndex = 0
while corpsesIndex < len(corpses):
corpse = corpses[corpsesIndex]
corpseValue = corpse.maxHealth / hero.distanceTo(corpse)
if corpseValue > bestValue:
bestCorpse = corpse
bestValue = corpseValue
corpsesIndex += 1
return bestCorpse
def findLunch():
enemies = hero.findEnemies()
enemyIndex = 0
lunch = None
closestLunch = 9999
while enemyIndex < len(enemies):
potentialLunch = enemies[enemyIndex]
if potentialLunch:
distance = hero.distanceTo(potentialLunch)
if potentialLunch.health <= 200 and distance < closestLunch:
lunch = potentialLunch
closestLunch = distance
enemyIndex += 1
return lunch
def findEnemyHero():
enemies = hero.findEnemies()
enemyIndex = 0
enemyHero = None
maxHealth = 0
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
if enemy.type == "Sorceror":
enemyHero = enemy
elif enemy.maxHealth > maxHealth:
enemyHero = enemy
maxHealth = enemy.maxHealth
enemyIndex += 1
return enemyHero
def spellBook(spell, target, distance):
if target:
e_distance = hero.distanceTo(target)
if e_distance <= distance:
if hero.canCast(spell, target):
hero.cast(spell, target)
def castSpells(target):
spellBook("fear", target, 25)
spellBook("poison-cloud", target, 30)
def raiseDead(c):
if c and hero.canCast("raise-dead"):
hero.moveXY(c.pos.x, c.pos.y)
pass
if c:
hero.cast("raise-dead")
def eatLunch(lunch):
if lunch and hero.isReady("devour"):
hero.move(lunch.pos)
hero.devour(lunch)
elif lunch:
hero.cast("drain-life", lunch)
#hero.moveXY(hero.pos.x + 5, hero.pos.y)
while True:
lunch = findLunch()
enemies = hero.findEnemies()
friends = hero.findFriends()
enemyHero = findEnemyHero()
summonArmy(enemyHero)
enemy = hero.findNearestEnemy()
items = hero.findItems()
item = findBestItem(items)
corpses = hero.findCorpses()
c = findBestCorpse(corpses)
castSpells(enemyHero)
raiseDead(c)
eatLunch(lunch)
if item:
itemB = None
items = hero.findItems()
itemB = findBestItem(items)
if itemB:
hero.move(itemB.pos)
enemy = hero.findNearestEnemy()
Note: I had to remove the Blue fox change shape function, as that word was not allowed by the codecombat word filter thing.
Thanks in advance,
Brenin Llwyd.