You could. Another idea would be to boost your own units with the spells.
That’s true. I could wait until they get close enough to the boulder and then boost them into it.
Or boost your snails so they get to the boulder faster.
I think I got it. Also it would be nice to have a system that checks to find the closest enemy unit and summon in that lane.
Yeah. Try something like:
def find():
lane0Closest = 999999
enemies = hero.findEnemies
for enemy in enemies:
if enemy.lane == 0:
if enemy.x < lane0Closest:
lane0Closest == enemy.x
#Do this with all the lanes
I didn’t see your message so I have a different method but I will try your to see if it works better. Mine beat the AI by a decent margin but I’m not sure it is the best.
Its probably hard to see my code so I’ll just send it to you.
def Push(lane):
hero.summon('snail', lane)
hero.summon('elemental', lane)
hero.summon('elemental', lane)
hero.summon('phoenix', lane)
hero.summon('phoenix', lane)
hero.summon('orb', lane)
hero.summon('orb', lane)
def Cast(lane):
boulder = hero.findBoulders(lane)
if boulder:
boulder = boulder[0]
units = hero.findMyUnits(lane)
unit = hero.findNearest(units)
if unit:
if unit.distanceTo(boulder) < 40:
hero.cast("burst", lane, unit.x + 2)
hero.cast("push", lane, unit.x)
def whereToSummon(lane):
enemyUnits = hero.findEnemyUnits(lane)
if not enemyUnits:
hero.summon('elemental', lane)
hero.summon('phoenix', lane)
hero.summon('phoenix', lane)
return False
lane = 0
while True:
whereToSummon(lane)
if whereToSummon(lane) == False:
lane += 1
Cast(lane)
Push(lane)
lane += 1
if lane > 2:
lane = 0
I could also check to see if there are enemy spells being cast on an empty lane to stop them from getting an easy win.
Maybe in your summoning code summon a phoenix and orb first, then summon your main body. That will help you gain a large advantage in a long game pushing war.
Keep in mind summoning units where there are none is good but you also want to defend against other attacks. Also be carefull with posting your code on here. Only post the code that people need to see. You dont want others to copy your code.
When you beat the second place guy:
But lose to random people:
Hey guys!
boulders = hero.findBoulders()[0]
distance = hero.distanceTo(boulders)
hero.cast("push", 0, distance)
# Do not copy!
I’ve been using this piece of code to find out the distance of the ball, but it always seems to miscalculate the distance and keep casting like 10-25(x-horizontal axis) off target.
Does anyone seem to know the problem?
hero.cast
accept (spell, lane, x)
, not distance.
boulder = hero.findBoulders()[0]
hero.cast("push", boulder.lane, boulder.x)
How can you help me with my new code. It looks a lot different than before. It is just not getting me as far as I would like.
Could you post it here so I can help?
I’ve gone back to my original code and am in 79th place but I think that if I can figure out what’s wrong with this code I could get a lot farther.
def summon_units(lane, units):
for unit in units:
hero.summon(unit, lane)
def cast_spells(lane, spells, boulder):
for spell in spells:
hero.cast(spell, lane, boulder.x - 1 if spell != "pull" else boulder.x + 25)
def Push(lane):
units = ['elemental', 'phoenix', 'orb', 'orb', 'snail', 'elemental', 'snail', 'phoenix', 'orb']
summon_units(lane, units)
def Cast(lane):
boulder = hero.findBoulders(lane)
if boulder:
boulder = boulder[0]
spells = ["push", "burst", "pull"]
cast_spells(lane, spells, boulder)
return (lane + 1) % 3
def find_closest_enemy():
lanes = [0, 1, 2]
closest_enemy_distance = float('inf')
closest_lane = None
for lane in lanes:
enemyUnits = hero.findEnemyUnits(lane)
enemyUnit = hero.findNearest(enemyUnits)
if enemyUnit:
distance = hero.distanceTo(enemyUnit)
if distance < closest_enemy_distance:
closest_enemy_distance = distance
closest_lane = lane
return closest_lane
def summon_in_other_lanes(lane):
units = ["phoenix", "phoenix", "orb"]
other_lanes = [0, 1, 2]
other_lanes.remove(lane)
for other_lane in other_lanes:
summon_units(other_lane, units)
lane = 0
while True:
closest_lane = find_closest_enemy()
if closest_lane is not None:
Push(closest_lane)
summon_in_other_lanes(closest_lane)
In your Push
code you might want to summon your snail in the front. It’s the beefiest and the faster units in the back will help push it.
Also, correct me if i’m wrong but are you calling your cast_spell
functions at all?
Done. I have also been thinking about changing the Cast(). I works ok but I was thinking that if I use the burst and push together in the middle, then use a pull like 5 meters off I would launch it. I call it in the Cast() function. Under spells.
Nice! Usually when summoning you want to summon a fast unit or two in the front to gain some momentum like a orb or phoenix, then summon all your other units in the order snail, elemental, phoenix, orb.
Something like this.
units = ['phoenix', 'phoenix', 'snail', 'elemental', 'orb', 'orb', 'elemental', 'snail', 'phoenix', 'orb']