diff --git a/TODO b/TODO index 2c9d89d..8c640fc 100644 --- a/TODO +++ b/TODO @@ -44,7 +44,6 @@ * AI: do not always move first, they are defenders * AI: add combination of random small move and actual maneuver, as producer * AI: evaluate drone area effects -* AI: produce random blast shots * AI: consider overheat/cooldown * AI: new duel page with producers/evaluators tweaking * Map: remove jump links that cross the radius of other systems diff --git a/src/core/ai/TacticalAIHelpers.spec.ts b/src/core/ai/TacticalAIHelpers.spec.ts index 5194d51..0b04ae1 100644 --- a/src/core/ai/TacticalAIHelpers.spec.ts +++ b/src/core/ai/TacticalAIHelpers.spec.ts @@ -46,7 +46,7 @@ module TS.SpaceTac.Specs { ]); }); - it("produces blast shots", function () { + it("produces interesting blast shots", function () { let battle = new Battle(); let ship = battle.fleets[0].addShip(); let weapon = TestTools.addWeapon(ship, 50, 1, 1000, 105); @@ -54,19 +54,19 @@ module TS.SpaceTac.Specs { TestTools.setShipAP(ship, 10); battle.playing_ship = ship; - let result = imaterialize(TacticalAIHelpers.produceBlastShots(ship, battle)); + let result = imaterialize(TacticalAIHelpers.produceInterestingBlastShots(ship, battle)); expect(result.length).toBe(0); let enemy1 = battle.fleets[1].addShip(); enemy1.setArenaPosition(500, 0); - result = imaterialize(TacticalAIHelpers.produceBlastShots(ship, battle)); + result = imaterialize(TacticalAIHelpers.produceInterestingBlastShots(ship, battle)); expect(result.length).toBe(0); let enemy2 = battle.fleets[1].addShip(); enemy2.setArenaPosition(700, 0); - result = imaterialize(TacticalAIHelpers.produceBlastShots(ship, battle)); + result = imaterialize(TacticalAIHelpers.produceInterestingBlastShots(ship, battle)); expect(result).toEqual([ new Maneuver(ship, weapon.action, Target.newFromLocation(600, 0)), new Maneuver(ship, weapon.action, Target.newFromLocation(600, 0)), @@ -75,7 +75,7 @@ module TS.SpaceTac.Specs { let enemy3 = battle.fleets[1].addShip(); enemy3.setArenaPosition(700, 300); - result = imaterialize(TacticalAIHelpers.produceBlastShots(ship, battle)); + result = imaterialize(TacticalAIHelpers.produceInterestingBlastShots(ship, battle)); expect(result).toEqual([ new Maneuver(ship, weapon.action, Target.newFromLocation(600, 0)), new Maneuver(ship, weapon.action, Target.newFromLocation(600, 0)), diff --git a/src/core/ai/TacticalAIHelpers.ts b/src/core/ai/TacticalAIHelpers.ts index c65cdb1..49b8784 100644 --- a/src/core/ai/TacticalAIHelpers.ts +++ b/src/core/ai/TacticalAIHelpers.ts @@ -54,7 +54,7 @@ module TS.SpaceTac { /** * Produce blast weapon shots, with multiple targets. */ - static produceBlastShots(ship: Ship, battle: Battle): TacticalProducer { + static produceInterestingBlastShots(ship: Ship, battle: Battle): TacticalProducer { // TODO Work with groups of 3, 4 ... let weapons = ifilter(getPlayableActions(ship), action => action instanceof FireWeaponAction && action.blast > 0); let enemies = battle.ienemies(ship.getPlayer(), true); @@ -65,6 +65,23 @@ module TS.SpaceTac { return result; } + /** + * Produce random blast weapon shots, on a grid. + */ + static produceRandomBlastShots(ship: Ship, battle: Battle, cells = 20, iterations = 2, random = RandomGenerator.global): TacticalProducer { + let weapons = ifilter(getPlayableActions(ship), action => action instanceof FireWeaponAction && action.blast > 0); + let candidates = icombine(weapons, scanArena(battle, cells, random)); + let result = imap(candidates, ([weapon, location]) => new Maneuver(ship, weapon, location)); + return result; + } + + /** + * Produce interesting then random blast shots + */ + static produceBlastShots(ship: Ship, battle: Battle): TacticalProducer { + return ichain(TacticalAIHelpers.produceInterestingBlastShots(ship, battle), TacticalAIHelpers.produceRandomBlastShots(ship, battle)); + } + /** * Produce drone deployments. */