|
- import { Creature } from './creature'
- import { Encounter } from './combat'
- import { LogEntry } from './interface'
-
- export interface AI {
- name: string;
- decide (actor: Creature, encounter: Encounter): LogEntry;
- }
-
- export class NoAI implements AI {
- name = "No AI"
- decide (actor: Creature, encounter: Encounter): LogEntry {
- throw new Error("This AI cannot be used.")
- }
- }
-
- /**
- * The RandomAI is **COMPLETELY** random. Good luck.
- */
- export class RandomAI implements AI {
- name = "Random AI"
- decide (actor: Creature, encounter: Encounter): LogEntry {
- const actions = encounter.combatants.flatMap(enemy => actor.validActions(enemy).map(action => ({
- target: enemy,
- action: action
- })))
- const chosen = actions[Math.floor(Math.random() * actions.length)]
- return chosen.action.execute(actor, chosen.target)
- }
- }
|