Cant get past level 4 please help
June 21, 2019 at 10:07amCant get past level 4 please help
June 21, 2019 at 10:07amHey guys i have been struggling with level 4 for a few days now and i really need someones help
here's my code:
class Player {
constructor() {
this._health = 20;
}
/**
- Plays a warrior turn.
- {Warrior} warrior The warrior. */
playTurn(warrior) {
if(warrior.health() > this.health) {var isInjured = 1;} else {var isInjured = 0;}if(warrior.health() < 10 && warrior.feel().isEmpty() && isInjured == 1) {warrior.think("Rest")warrior.think(this.health)warrior.rest()} else if(warrior.feel().isEmpty()) {warrior.think("Walk")warrior.think(this.health)warrior.walk()} else if(warrior.feel().isUnit()) {warrior.think("Attack")warrior.think(this.health)warrior.attack()}if(1 == 1) {this.health = warrior.healthwarrior.think("1=1")}
}
}
July 3, 2019 at 5:26pm
The problem here is that you are not doing anything with the archers of that level. They can shoot you from a distance, so if you just stay resting in place just because you don't see any enemy in front of you, you can still die from the shoots (you receive more damage that what you can heal).
On another point:
You're using numbers to have boolean values, you should use basic boolean values and that should make some places of the code a bit cleanner (like changing the isInjured == 1 by isInjured)
You could read some of the docs related to AI that are linked on the api docs. This could be made much cleaner with a basic state machine, and with that, probabdly, you are going to see some more plausible solutions.
Sorry for my bad english, hope this helps a bit.