GameReadyGoap 5.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package GameReadyGoap --version 5.0.0                
NuGet\Install-Package GameReadyGoap -Version 5.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GameReadyGoap" Version="5.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GameReadyGoap --version 5.0.0                
#r "nuget: GameReadyGoap, 5.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GameReadyGoap as a Cake Addin
#addin nuget:?package=GameReadyGoap&version=5.0.0

// Install GameReadyGoap as a Cake Tool
#tool nuget:?package=GameReadyGoap&version=5.0.0                

<img src="https://github.com/Joy-less/GameReadyGoap/blob/main/Assets/Icon.jpg?raw=true" width=256/>

Game Ready Goap

NuGet

An easy-to-use implementation of GOAP (Goal-Oriented Action Planning) to control game characters in C#.

Features

  • Simple and performant, made for game development
  • Expressive with minimal boilerplate
  • Get as close as possible to "best-effort" goals

GOAP vs HTN

This library is parallel to Game Ready Htn, an implementation of HTN.

Goal-Oriented Action Planning and Hierarchical Task Networks are both powerful choices for controlling NPCs. HTN defines a structured hierarchy of nested tasks that should be completed. GOAP defines a set of goals and a set of actions that can be combined to reach those goals.

HTN is simpler, faster and more predictable because the tasks use a predefined order. It's suitable for most game enemies which only have a limited set of actions. It's an implementation of a behaviour tree.

GOAP is more flexible and powerful because the actions can be combined in very complex ways. It's suitable for agents with lots of actions and strategies to consider, such as in Real-Time Strategy games.

This Reddit discussion provides more comparisons between GOAP, HTN and behaviour trees.

Usage

First, create an agent with initial states, goals and actions:

GoapAgent Agent = new() {
    // These describe the current state of your agent (character).
    States = new() {
        ...
    },
    // These are the states your agent is trying to achieve.
    Goals = [
        ...
    ],
    // These are the ways your agent can change their states.
    Actions = [
        ...
    ],
};

Then, finding a plan is easy:

Agent.FindPlan(); // or Agent.FindPlan(Goal);

Executing plans is also easy:

Plan.Execute(Agent, Action => {
    ...
});

Example

A farmer is balancing tending to his crops with resting. He can farm to increase his crop health, which requires energy, or sleep to increase his energy.

GoapAgent Farmer = new() {
    States = new() {
        ["Energy"] = 100,
        ["CropHealth"] = 0,
    },
    Goals = [
        new GoapGoal("TendToCrops") {
            Objectives = [
                new GoapCondition() {
                    State = "CropHealth",
                    Comparison = GoapComparison.GreaterThanOrEqualTo,
                    Value = 100,
                    BestEffort = true,
                },
            ],
        },
    ],
    Actions = [
        new GoapAction("Farm") {
            Effects = [
                new GoapEffect() {
                    State = "CropHealth",
                    Operation = GoapOperation.IncreaseBy,
                    Value = 20,
                },
                new GoapEffect() {
                    State = "Energy",
                    Operation = GoapOperation.DecreaseBy,
                    Value = 30,
                },
            ],
            Requirements = [
                new GoapCondition() {
                    State = "Energy",
                    Comparison = GoapComparison.GreaterThanOrEqualTo,
                    Value = 30,
                },
            ],
        },
        new GoapAction("Sleep") {
            Effects = [
                new GoapEffect() {
                    State = "Energy",
                    Operation = GoapOperation.IncreaseBy,
                    Value = 5,
                },
            ],
        },
    ],
};
Farmer.FindPlan();

We get 15 actions which bring us to our goal:

Action Energy Crop Health
- 100 0
Farm 70 20
Farm 40 40
Farm 10 60
Sleep 15 60
Sleep 20 60
Sleep 25 60
Sleep 30 60
Farm 0 80
Sleep 5 80
Sleep 10 80
Sleep 15 80
Sleep 20 80
Sleep 25 80
Sleep 30 80
Farm 0 100

Tips

Avoid near-impossible goals

Instead of aiming to set the player's health = 0, aim for ⇐ 0. Best-effort plans are slow to find because plans that reach the goal are always prioritised.

Avoid lots of actions

The more actions an agent has, the longer it will take to find a plan.

Know the limitations

GOAP requires a lot of trial and error to use successfully. If configured poorly, it may result in unpredictable plans that are feasible but not believable.

Special Thanks

  • F.E.A.R. for creating the GOAP algorithm.
  • This Is Vini for explaining the GOAP algorithm.
  • SimpleGOAP for guidance when implementing the action planner.
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.1.0 71 11/19/2024
5.0.0 71 11/19/2024
4.0.0 65 11/19/2024
3.0.0 74 11/16/2024
2.1.0 139 10/18/2024
2.0.0 83 10/7/2024
1.2.0 89 10/5/2024
1.1.0 93 10/5/2024
1.0.0 88 10/5/2024