Crates.io | dogoap |
lib.rs | dogoap |
version | 0.3.0 |
source | src |
created_at | 2024-07-22 13:45:50.375838 |
updated_at | 2024-08-11 14:21:32.938683 |
description | dogoap |
homepage | https://github.com/victorb/dogoap |
repository | |
max_upload_size | |
id | 1311112 |
size | 69,983 |
dogoap
- Data-Oriented, Goal-Oriented Action PlanningGOAP 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.
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.
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());