Skip to content

A lightweight, pure functional GOAP solver in TypeScript for creating complex AI agent behavior in games and simulations

License

Notifications You must be signed in to change notification settings

13luck/goap-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GOAP Solver

A lightweight, pure functional GOAP solver in TypeScript for creating complex AI agent behavior in games and simulations.

Features

  • ✨ Pure functional
  • 🔢 Boolean and Numeric facts
  • 📜 Declarative
  • ✅ Written in TypeScript
  • 🗜️ Zero dependencies

References

Installation

npm i goap-solver

Usage

import { planner, Action, GoalFacts } from 'goap-solver'


// define world state
const state = {
  hasDocument: false,
  money: 0,
  beer: 2,
} satisfies GoalFacts

// define what we want to achieve
const goal = { beer: state.beer + 1 } satisfies GoalFacts

// define available actions
const a: Action = {
  name: 'GetDocument',
  preconditions: { hasDocument: false },
  effects: { hasDocument: true },
  priority: 1,
}
const b: Action = {
  name: 'GetMoney',
  preconditions: { money: 0 },
  effects: { money: +10 },
  priority: 2,
}
const c: Action = {
  name: 'BuyBeer',
  preconditions: { hasDocument: true, money: 10 },
  effects: { beer: +1, money: -10 },
}

const actions = [c, b, a]
const plan = planner(state, goal, actions)
const result = plan?.map(({ name }) => name)

expect(result).toEqual(['GetMoney', 'GetDocument', 'BuyBeer'])

License

MIT © 2025-present, @13luck

About

A lightweight, pure functional GOAP solver in TypeScript for creating complex AI agent behavior in games and simulations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published