GOAP
GOAP (Goal-Oriented Action Planning) is a form of declarative programming used in artificial intelligence systems. It involves defining a set of actions that can be performed by an agent, each with preconditions and effects, to achieve specified goals within a dynamic environment.
Action planning is made using the A* search algorithm to find the optimal plan of action to achieve the desired state. Performance is improved by using a heuristic function to estimate the cost of each action.
Example
Import the library:
And define the current State of the world as:
=
And the goal we would like to achieve as:
=
And then we define a set of possible Actions:
=
Note: The
Actionclass takes four arguments:name,cost,preconditions, andeffects.
Finally, we can create_plan to find the optimal plan of action to achieve the desired state:
, =
This particular example will return the following plan:
Plan found: gather_wood -> gather_wood -> gather_wood -> build_fire -> sit_by_fire | Total Cost: 8
Quickstart
Clone the repository and set the root folder as the current working directory:
git clone https://github.com/FreddyWordingham/GOAP.git goap
cd goap
Install the package using Poetry:
poetry env use python@3.10
poetry install
And then run one of the example scripts:
poetry run python scripts/run.py