GOAP-AI
Generate a plan using the GOAP algorithm.
Usage
Define the agent's world view, goals, and actions in a config.yml file.
Agent's world view:
state:
properties:
energy: 50
health: 20
consciousness: 10
raw_meat: 0
cooked_meat: 0
wood: 0
fire: 0
Agent's goals:
goals:
- weight: 1
property: "energy"
target: 100
- weight: 1
property: "health"
target: 30
- weight: 1
property: "consciousness"
target: 10
- weight: 1
property: "fire"
target: 1
Agent's action set:
actions:
- label: "gather_wood"
duration: 2
deltas:
energy: -10
consciousness: -10
wood: 10
- label: "build_fire"
duration: 1
deltas:
energy: -5
consciousness: -5
wood: -10
fire: 10
- label: "hunt"
duration: 2
deltas:
energy: -10
health: -2
consciousness: -40
raw_meat: 3
- label: "cook_meat"
duration: 1
deltas:
energy: -5
health: 0
consciousness: -5
raw_meat: -1
cooked_meat: 1
fire: -1
- label: "eat_raw_meat"
duration: 1
deltas:
energy: 5
health: 2
consciousness: -10
raw_meat: -1
- label: "eat_cooked_meat"
duration: 1
deltas:
energy: 30
health: 5
consciousness: -10
cooked_meat: -1
- label: "exercise"
duration: 2
deltas:
energy: -10
health: 5
consciousness: -20
- label: "sleep"
duration: 8
deltas:
energy: -10
health: 5
consciousness: 80
- label: "sleep_with_fire"
duration: 8
deltas:
health: 10
consciousness: 100
fire: -1
- label: "wait"
duration: 1
deltas:
energy: -2
consciousness: -1
Then run the program with the following command:
You'll see the agent's plan to achieve its goals:
# Solution:
Plan found with score 0.00 and time 31
# Plan:
Step 1) d=1.77 t=8 sleep
Step 2) d=1.87 t=10 gather_wood
Step 3) d=0.92 t=11 build_fire
Step 4) d=0.75 t=19 sleep_with_fire
Step 5) d=0.85 t=21 hunt
Step 6) d=0.90 t=22 cook_meat
Step 7) d=0.60 t=23 eat_cooked_meat
Step 8) d=0.65 t=24 cook_meat
Step 9) d=0.35 t=25 eat_cooked_meat
Step 10) d=0.40 t=26 cook_meat
Step 11) d=0.10 t=27 eat_cooked_meat
Step 12) d=0.20 t=29 hunt
Step 13) d=0.25 t=30 cook_meat
Step 14) d=0.00 t=31 eat_cooked_meat
# Final state:
consciousness: 35
wood: 0
energy: 105
fire: 5
cooked_meat: 0
raw_meat: 2
health: 51
API
The world state is a list of key-value pairs. The goals are a list of key-value pairs with a target value and a weight. The actions are a list of key-value pairs with a label, duration, and a list of key-value pairs which represent the state changes when the action is executed.
State -> GOAP -> Plan