I gotta admit, I’m very good at programming, but this level just trumps me.
My code:
function findUnitWithLeastHealth () {
let friends = hero.findFriends();
var worstUnit = friends[0];
for (let friend of friends) if (friend.health < worstUnit.health) worstUnit = friend;
if (worstUnit.health > worstUnit.maxHealth/1.25) return null;
return worstUnit;
}
function withinType (type, notTypes) {
if (!(notTypes)) notTypes = [];
var section;
var enemiesInSection = [];
if (hero.pos.x < 100) section = 1;
else if (hero.pos.x < 158) section = 2;
else section = 3;
var list;
if (type) list = hero.findByType(type);
else list = hero.findEnemies();
for (let enemy of list) {
var enemySection;
if (hero.pos.x < 100) enemySection = 1;
else if (hero.pos.x < 158) enemySection = 2;
else enemySection = 3;
if (enemySection == section && notTypes.indexOf(enemy.type) == -1) enemiesInSection.push(enemy);
}
return enemiesInSection;
}
while (true) {
let enemies = hero.findEnemies();
var enemiesToAttack = [];
for (let enemy of enemies) if (enemy.type != "tower" && (enemy.type != "door" || withinType(undefined, ["catapult", "tower"]))) enemiesToAttack.push(enemy);
let enemy = hero.findNearest(enemiesToAttack);
if (enemy) {
if (hero.distanceTo(enemy) <= 3) hero.attack(enemy);
else hero.move(enemy.pos);
}
for (let unit of hero.findFriends()) {
if (unit.type == "paladin") {
hero.command(unit, "move", {x: unit.pos.x+1, y: unit.pos.y});
let unitToHeal = findUnitWithLeastHealth();
if (unitToHeal && unit.canCast("heal")) hero.command(unit, "cast", "heal", unitToHeal);
else {
let unitEnemy = unit.findNearestEnemy();
if (unitEnemy) hero.command(unit, "attack", unitEnemy);
}
} else {
let unitEnemy = unit.findNearestEnemy();
if (unitEnemy) hero.command(unit, "attack", unitEnemy);
}
}
}
don’t understand why it won’t at least go inside the inner gate…
Also, I know there could be some better versions, right now, I’m just focusing on making it work. ._.