Nope, two of my archers died before I could get to fifty.
do you have the code that makes the soldiers stay in a circle
the original code
if you do just put both build archer at the very top
I’m pretty sure I do.
ok then try submitting a few times thats how my brother solved it
That’s what I did multiple times…
did you get close to winning
Not even close! I was only a quarter through!
really
can i see your code
this.commandSoldier = function(soldier, soldierIndex, numSoldiers) {
var angle = Math.PI * 2 * soldierIndex / numSoldiers;
var defendPos = {x: 41, y: 40};
defendPos.x += 10 * Math.cos(angle);
defendPos.y += 10 * Math.sin(angle);
this.command(soldier, "defend", defendPos);
};
// Find the strongest target (most health)
// This function returns something! When you call the function, you will get some value back.
this.findStrongestTarget = function() {
var mostHealth = 0;
var bestTarget = null;
var enemies = this.findEnemies();
// Figure out which enemy has the most health, and set bestTarget to be that enemy.
for(var i=0;i<enemies.length;i++)
if(enemies[i].health > mostHealth){
mostHealth=enemies[i].health;
bestTarget=enemies[i];
}
// Only focus archers' fire if there is a big ogre.
if (bestTarget && bestTarget.health > 15) {
return bestTarget;
} else {
return null;
}
};
// If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
this.commandArcher = function(archer) {
var nearest = archer.findNearestEnemy();
if(archerTarget) {
this.command(archer, "attack", archerTarget);
} else if(nearest) {
this.command(archer, "attack", nearest);
}
};
var archerTarget = null;
loop {
if (this.gold >= 50){
this.summon("archer");
this.summon("archer");
}
// If archerTarget is dead or doesn't exist, find a new one.
if(!archerTarget || archerTarget.health <= 0) {
// Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = this.findStrongestTarget();
}
var friends = this.findFriends();
var soldiers = this.findByType("soldier");
var archers = this.findByType("archer");
for(var i=0; i < soldiers.length; i++) {
var soldier = soldiers[i];
this.commandArcher(soldier, i, soldiers.length);
}
// use commandArcher() to command your archers
for (var a=0; a < archers.length; a++) {
var archer = archers[a];
this.commandArcher(archer);
}
}
i used python
mabye its because python is different
i put build archer at the top before the reloaded code
Once again I recommend reading through your code line-by-line. Start at your loop
and check to make sure everything makes sense. Are you calling the wrong function anywhere?
I am saying this because I can see the problem with your code. It is directly in the main loop
. So give it a look again, please.
oh and you dont summon you build
with the stone hammer
it makes it so that the archers attack without having to do command
i also did
if self.gold >= 25:
build the archer
i ended up with 10 archers
- Your error is in the soldier command section of your code:
for(var i=0; i < soldiers.length; i++) {
var soldier = soldiers[i];
this.commandArcher(soldier, i, soldiers.length);
}
[details=Solution] Use
this.commandSoldiersoldier, i, soldiers.length);
[/details]
- I will not recommend to summon archers this level: the enemy is codded to attack in much greater numbers if they see an archer outside the soldier circle. Every summoned archers appears outside the circle so you will have to fight extra enemies each time you summon.
Tested the code and it still works with no summon or summon once per turn (this.gold>=25) …
no you dont summon you build i ended up with 10 archers
How do you make your code look like that?
you format
message
no like this
the key on the top left corner three times before code and after code
code