Goap Js Save

A proof-of-concept implementation of Goal Oriented Action Planning in JavaScript

Project README

What is this?

Good question. This is a simple implementation of Goal-Oriented Action Planning (G.O.A.P.) in JavaScript.

What can I do with this?

If you're making a game with NPC characters that you want to appear realistic and smart, the GOAP can be a great option.

Example

Given the following world state, goals and actions:

export const worldState = {
  axe_available: true,
  player: {
    axe_equipped: false,
    wood: 0
  }
};

export const actions = {
  chopWood: {
    condition: s => s.player.axe_equipped,
    effect: s => {
      s.player.wood++;
      return s;
    },
    cost: s => 2
  },
  getAxe: {
    condition: s => !s.player.axe_equipped && s.axe_available,
    effect: s => {
      s.player.axe_equipped = true;
      return s;
    },
    cost: s => 2
  },
  gatherWood: {
    condition: s => true,
    effect: s => {
      s.player.wood++;
      return s;
    },
    cost: s => 5
  }
};

export const goals = {
  collectWood: {
    label: "Collect Wood",
    validate: (prevState, nextState) => {
      return nextState.player.wood > prevState.player.wood;
    }
  }
};

The GOAP Planner will create the following plan:

{
  "cost": 4,
  "goal": {
    "label": "Collect Wood"
  },
  "actions": [
    "getAxe",
    "chopWood"
  ]
}

For a more complex example, see Sim 2.

Further reading

Check out the following resource:

Running the code

  1. Install the dependencies npm init or yarn
  2. Run the test npm run test or yarn test
Open Source Agenda is not affiliated with "Goap Js" Project. README Source: wmdmark/goap-js
Stars
82
Open Issues
9
Last Commit
1 year ago
Repository
License
ISC

Open Source Agenda Badge

Open Source Agenda Rating