dogoap

Crates.iodogoap
lib.rsdogoap
version0.3.0
sourcesrc
created_at2024-07-22 13:45:50.375838
updated_at2024-08-11 14:21:32.938683
descriptiondogoap
homepagehttps://github.com/victorb/dogoap
repository
max_upload_size
id1311112
size69,983
Victor Bjelkholm (victorb)

documentation

README

dogoap - Data-Oriented, Goal-Oriented Action Planning

License Crates.io Downloads Docs ci

GOAP implemented in data-oriented way to facilitate dynamically setting up states/actions/goals rather than statically

This is a standalone Rust library for doing GOAP declaratively.

Pseudo-example

Given a current state like this:

is_hungry = true

And with the following available actions:

eat_action = Mutator::set("is_hungry", false)

And with a goal like this:

is_hungry = false

The magical planner can figure out the best path of actions to reach that goal. In this case, the best plan is just one eat_action which results in the is_hungry state variable to be set to false, a very simplistic example.

That's the basics. Of course, things get more interesting once we start to include preconditions, multiple actions and multiple state variables, and the planner needs to figure out the right way of reaching there.

Code / API example

This is the actual API of the library:

use dogoap::prelude::*;

let start = LocalState::new().with_datum("is_hungry", Datum::Bool(true));

let goal = Goal::new().with_req("is_hungry", Compare::Equals(Datum::Bool(false)));

let eat_action = Action {
    key: "eat".to_string(),
    preconditions: vec![],
    effects: vec![Effect {
        action: "eat".to_string(),
        mutators: vec![Mutator::Set("is_hungry".to_string(), Datum::Bool(false))],
        state: LocalState::new(),
        cost: 1,
    }],
};

let actions: Vec<Action> = vec![eat_action];

let plan = make_plan(&start, &actions[..], &goal);

print_plan(plan.unwrap());
Commit count: 0

cargo fmt