Feast 2.0!
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

31 řádky
847 B

  1. import { Creature } from './creature'
  2. import { Encounter } from './combat'
  3. import { LogEntry } from './interface'
  4. export interface AI {
  5. name: string;
  6. decide (actor: Creature, encounter: Encounter): LogEntry;
  7. }
  8. export class NoAI implements AI {
  9. name = "No AI"
  10. decide (actor: Creature, encounter: Encounter): LogEntry {
  11. throw new Error("This AI cannot be used.")
  12. }
  13. }
  14. /**
  15. * The RandomAI is **COMPLETELY** random. Good luck.
  16. */
  17. export class RandomAI implements AI {
  18. name = "Random AI"
  19. decide (actor: Creature, encounter: Encounter): LogEntry {
  20. const actions = encounter.combatants.flatMap(enemy => actor.validActions(enemy).map(action => ({
  21. target: enemy,
  22. action: action
  23. })))
  24. const chosen = actions[Math.floor(Math.random() * actions.length)]
  25. return chosen.action.execute(actor, chosen.target)
  26. }
  27. }