rust_goap
A lightweight, efficient Goal-Oriented Action Planning (GOAP) library for Rust, designed for game AI and decision-making systems.
Features
- Simple API: Easy-to-use interface for defining actions, goals, and world state
- Efficient Planning: Uses A* pathfinding algorithm with custom heuristics
- Flexible State: Supports various value types (bool, i64, f64)
- Cost-Based Optimization: Finds the lowest-cost path to achieve goals
- Human-Readable Output: Built-in plan formatting for debugging and visualization
- Minimal Dependencies: Only depends on the
pathfindingcrate - Future JSON Support: Planned support for JSON serialization to create actions dynamically
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use *;
Core Concepts
World State
The current state of the world, represented as a key-value map:
let state = new
.set
.set
.set;
Goal
Desired states to achieve, with assertions on values:
let goal = new
.with
.with;
Action
Actions that can be performed, with preconditions and effects:
let heal = new
.with_precondition
.with_effect;
Effect
Changes to the world state when an action is performed:
Effect
Mutation Types
Mutation::set(key, value)- Set a valueMutation::increment(key, amount)- Increment a numeric valueMutation::decrement(key, amount)- Decrement a numeric valueMutation::delete(key)- Remove a key from the state
Assertion Types
Assert::eq(value)- Equal toAssert::not_eq(value)- Not equal toAssert::gt(value)- Greater thanAssert::gt_eq(value)- Greater than or equal toAssert::lt(value)- Less thanAssert::lt_eq(value)- Less than or equal to
Examples
The repository includes several examples:
Basic Example
Complex Planning Example
API Documentation
Main Functions
make_plan(start, actions, goal)- Find optimal plan from start to goalmake_plan_with_strategy(strategy, start, actions, goal)- Plan with specific strategyget_effects_from_plan(plan)- Extract actions and effects from a planformat_plan(plan)- Format plan as human-readable string
Core Types
WorldState- Represents the current state of the worldGoal- Desired state with requirementsAction- Action that can be performedEffect- Changes caused by an actionNode- Internal planning node (graph search)PlanningStrategy- Planning algorithm strategy
Performance
The library uses the A* algorithm with the following optimizations:
- Custom heuristic based on goal distance
- Efficient state comparison and cloning
- Early pruning of invalid action sequences
Roadmap
Planned Features
-
JSON Serialization: Create actions, goals, and world states from JSON configuration
-
Plugin System: Extensible action and effect system
-
Visualization Tools: Graph visualization of planning process
Use Cases
- Game AI: NPC behavior planning, enemy AI, companion AI
- Simulations: Agent-based modeling, decision systems
- Automation: Workflow planning, process optimization
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m "Add some amazing feature") - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Formatting
This project uses rustfmt for consistent code formatting. The configuration is defined in .rustfmt.toml.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
This project was inspired by and extracts core GOAP concepts from the dogoap repository, a Rust implementation of Goal-Oriented Action Planning. rust_goap builds upon these foundations with a focus on simplicity, performance, and future extensibility including JSON serialization support.
rust_goap - Simple, efficient, and extensible goal-oriented planning for Rust applications.