Giter Club home page Giter Club logo

rgoap's Introduction

rgoap

crates.io Build Status Coverage Status

A simplistic Rust implementation of Orkin's Goal-Oriented Action-Planner (GOAP), as described on his website.

Find the crate documentation on docs.rs, or here on Github.

This implementation is simplistic, as it doesn't handle many features, such as procedural pre- and post-conditions, dynamic action cost, non-binary world state, etc. But it is very short (thanks to the pathfinding crate by Samuel Tardieu). It has been written as a project to learn more about Rust - use with caution.

Usage

Add the rgoap dependency to Cargo.toml:

[dependencies]
rgoap = "0.1"

And use the crate as such:

extern crate rgoap;

use rgoap::{State, Action, plan};

fn main() {
    // The actions your planner will be allowed to use.
    let mut walk_to_dog = Action::new("walk_to_dog".to_string(), 1);
    walk_to_dog.pre_conditions.insert("dog_person".to_string(), true);
    walk_to_dog.post_conditions.insert("near_dog".to_string(), true);

    let mut dog_wiggles_tail = Action::new("dog_wiggles_tail".to_string(), 1);
    dog_wiggles_tail.pre_conditions.insert("dog_happy".to_string(), true);
    dog_wiggles_tail.post_conditions.insert("tails_wiggling".to_string(), true);

    let mut pet_dog = Action::new("pet_dog".to_string(), 1);
    pet_dog.pre_conditions.insert("near_dog".to_string(), true);
    pet_dog.post_conditions.insert("dog_happy".to_string(), true);

    let possible_actions = [walk_to_dog, pet_dog, dog_wiggles_tail];

    // This is the initial state of the world.
    let mut initial_state = State::new();
    initial_state.insert("near_dog".to_string(), false);
    initial_state.insert("dog_person".to_string(), true);
    initial_state.insert("dog_happy".to_string(), false);
    initial_state.insert("tails_wiggling".to_string(), false);

    // And this is the target state. Note that it doesn't have to include all of the states.
    let mut goal_state = State::new();
    goal_state.insert("tails_wiggling".to_string(), true);

    // Let's find which actions needs to happen to get there.
    let planned_actions = plan(&initial_state, &goal_state, &possible_actions).unwrap();

    // Are the actions what we expected?
    let planned_actions_names: Vec<String> =
        planned_actions.iter().map(|&action| action.name.clone()).collect();
    let expected_actions_names =
        vec!["walk_to_dog".to_string(), "pet_dog".to_string(), "dog_wiggles_tail".to_string()];

    assert_eq!(planned_actions_names, expected_actions_names);
}

License

MIT - See LICENSE file.

rgoap's People

Contributors

tynril avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.