my code is working however i cant get past 30 seconds on the actual objectives. if you can see any problems in my code let me know and what i can avoid to do next time. thanks
function chooseStrategy() {
var enemies = hero.findEnemies();
// If you can summon a griffin-rider, return "griffin-rider"
if (hero.costOf("griffin-rider") <= hero.gold){
return "griffin-rider";
}
var fangriders = hero.findByType("fangrider");
for (var i =0; i < fangriders.length; i++){
var fangrider = fangriders[i];
if (fangrider.pos.x < 38) {
return "____";
}
}
return "collect-coins";
// Otherwise, return "collect-coins"
}
function commandAttack() {
// Command your griffin riders to attack ogres.
var griffins = hero.findFriends();
var enemies = hero.findEnemies();
for (var i =0; i < griffins.length; i++){
var griffin = griffins[i];
var enemy = griffin.findNearest(enemies);
if (enemy) {
hero.command(griffin, "attack", enemy);
}
else {
hero.command(griffin, "move", {"x":hero.pos.x + 20, "y":griffin.pos.y});
}
}
}
function pickUpCoin() {
// Collect coins
var items = hero.findItems();
var item = hero.findNearest(items);
if(item){
hero.move(item.pos);
}
}
function heroAttack() {
// Your hero should attack fang riders that cross the minefield.
var enemy = hero.findNearest(hero.findByType("fangriders"));
if (enemy && hero.distanceTo(enemy) < 15){
hero.attack(enemy);
}
}
while(true) {
commandAttack();
var strategy = chooseStrategy();
// Call a function, depending on what the current strategy is.
if (strategy == "griffin-rider"){
hero.summon("griffin-rider");
}
else if (strategy == "___"){
heroAttack();
}
else if (strategy == "collect-coins"){
pickUpCoin();
}
}