Utility AI system: scores actions by consideration curves and picks the best.
Usage:
const ai = new UtilityAI<EnemyContext>();ai.addAction('attack', [ { name: 'closeEnough', curve: 'linear', inputFn: ctx => 1 - ctx.distance / 200 }, { name: 'hasAmmo', curve: 'binary', inputFn: ctx => ctx.ammo > 0 ? 1 : 0 },]);ai.addAction('flee', [ { name: 'lowHealth', curve: 'quadratic', inputFn: ctx => 1 - ctx.health / 100 },]);const best = ai.evaluate(context); // → 'attack' or 'flee' Copy
const ai = new UtilityAI<EnemyContext>();ai.addAction('attack', [ { name: 'closeEnough', curve: 'linear', inputFn: ctx => 1 - ctx.distance / 200 }, { name: 'hasAmmo', curve: 'binary', inputFn: ctx => ctx.ammo > 0 ? 1 : 0 },]);ai.addAction('flee', [ { name: 'lowHealth', curve: 'quadratic', inputFn: ctx => 1 - ctx.health / 100 },]);const best = ai.evaluate(context); // → 'attack' or 'flee'
Utility AI system: scores actions by consideration curves and picks the best.
Usage: