2017-02-21 21:16:18 +00:00
|
|
|
/// <reference path="Maneuver.ts" />
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac.Specs {
|
2017-10-26 21:47:13 +00:00
|
|
|
testing("TacticalAI", test => {
|
2017-02-21 21:16:18 +00:00
|
|
|
class FixedManeuver extends Maneuver {
|
|
|
|
score: number;
|
|
|
|
constructor(score: number) {
|
2017-05-18 21:10:16 +00:00
|
|
|
let battle = new Battle();
|
|
|
|
let ship = battle.fleets[0].addShip();
|
2017-11-29 22:03:58 +00:00
|
|
|
super(ship, new BaseAction("nothing"), new Target(0, 0));
|
2017-02-21 21:16:18 +00:00
|
|
|
this.score = score;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// producer of FixedManeuver from a list of scores
|
2017-02-24 00:34:31 +00:00
|
|
|
let producer = (...scores: number[]) => imap(iarray(scores), score => new FixedManeuver(score));
|
2017-03-09 17:11:00 +00:00
|
|
|
let applied: number[] = [];
|
2017-02-21 21:16:18 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
test.setup(function () {
|
|
|
|
test.check.patch(console, "log", null);
|
2017-02-21 21:16:18 +00:00
|
|
|
applied = [];
|
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("applies the highest evaluated maneuver", check => {
|
2017-05-18 21:10:16 +00:00
|
|
|
let battle = new Battle();
|
2017-08-23 17:59:22 +00:00
|
|
|
let ship = battle.fleets[0].addShip();
|
2017-10-25 22:45:53 +00:00
|
|
|
TestTools.setShipPlaying(battle, ship);
|
2017-08-23 17:59:22 +00:00
|
|
|
ship.playing = true;
|
2017-12-21 19:04:54 +00:00
|
|
|
|
|
|
|
let ai = new TacticalAI(ship, maneuver => {
|
|
|
|
if (maneuver instanceof FixedManeuver) {
|
|
|
|
applied.push(maneuver.score);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}, false, Timer.synchronous);
|
2017-05-17 23:03:33 +00:00
|
|
|
|
2017-10-29 21:08:55 +00:00
|
|
|
check.patch(ai, "getDefaultProducers", () => [
|
2017-05-17 23:03:33 +00:00
|
|
|
producer(1, -8, 4),
|
|
|
|
producer(3, 7, 0, 6, 1)
|
|
|
|
]);
|
2017-10-29 21:08:55 +00:00
|
|
|
check.patch(ai, "getDefaultEvaluators", () => [
|
2017-05-17 23:03:33 +00:00
|
|
|
(maneuver: Maneuver) => (<FixedManeuver>maneuver).score
|
|
|
|
]);
|
2017-02-21 21:16:18 +00:00
|
|
|
|
|
|
|
ai.play();
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(applied, [7]);
|
2017-02-21 21:16:18 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|