module TK.SpaceTac { /** * AI that produces random valid plans, exploring the whole set of possibilities */ export class BruteAI extends AbstractAI { getPlanProducer(): AIPlanProducer { const builder = () => this.getRandomPlan(); function* producer() { while (true) { yield builder(); } } return producer(); } /** * Get a single random plan */ getRandomPlan(): AIPlan { const planning = new TurnPlanning(this.battle, this.player); for (let ship of this.battle.ships.iterator()) { if (ship.isPlayedBy(this.player)) { for (let action of ship.actions.listAll()) { if (action instanceof MoveAction) { if (this.random.bool()) { this.addMove(planning, ship, action); } } } } } return new AIPlan(planning.getTurnPlan(), this.battle, this.player); } /** * Add a random move action */ addMove(planning: TurnPlanning, ship: Ship, action: MoveAction): void { const distance = this.random.random() * (action.max_distance - action.min_distance) + action.min_distance; const angle = this.random.random() * Math.PI * 2; planning.addAction(ship, action, distance, angle); } } }