{"id":17219505,"url":"https://github.com/kelindar/goap","last_synced_at":"2025-04-13T23:43:26.217Z","repository":{"id":206715641,"uuid":"717537988","full_name":"kelindar/goap","owner":"kelindar","description":"Goal-Oriented Action Planning - in Go","archived":false,"fork":false,"pushed_at":"2023-11-12T14:42:05.000Z","size":87,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T13:51:14.844Z","etag":null,"topics":["ai","goal-oriented-action-planning","goap","planner"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kelindar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["kelindar"]}},"created_at":"2023-11-11T19:13:15.000Z","updated_at":"2025-02-28T11:39:40.000Z","dependencies_parsed_at":"2023-11-11T20:24:51.126Z","dependency_job_id":"2987ddeb-dae7-4b1c-81a9-a5e37e903d4b","html_url":"https://github.com/kelindar/goap","commit_stats":null,"previous_names":["kelindar/goap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelindar%2Fgoap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelindar%2Fgoap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelindar%2Fgoap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kelindar%2Fgoap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kelindar","download_url":"https://codeload.github.com/kelindar/goap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248799661,"owners_count":21163398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","goal-oriented-action-planning","goap","planner"],"created_at":"2024-10-15T03:50:01.252Z","updated_at":"2025-04-13T23:43:26.192Z","avatar_url":"https://github.com/kelindar.png","language":"Go","funding_links":["https://github.com/sponsors/kelindar"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg width=\"270\" height=\"110\" src=\".github/logo.png\" border=\"0\" alt=\"kelindar/goap\"\u003e\n\u003cbr\u003e\n\u003cimg src=\"https://img.shields.io/github/go-mod/go-version/kelindar/goap\" alt=\"Go Version\"\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/kelindar/goap\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com/kelindar/goap\" alt=\"PkgGoDev\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/kelindar/goap\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/kelindar/goap\" alt=\"Go Report Card\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/kelindar/goap\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/kelindar/goap/badge.svg\" alt=\"Coverage\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## GOAP: Goal-Oriented Action Planning in Go\n\n**GOAP**, standing for Goal-Oriented Action Planning, is a library developed in Go, designed to facilitate the creation of plans to achieve specific goals. Its primary application is in AI planning for areas such as game development, robotics, and other fields requiring complex decision-making. GOAP combines the simplicity of Go with the complexity of action planning, making it a practical tool for developers in need of reliable AI solutions.\n\n### Key Features\n\n1. **High Performance**: This library is built with performance in mind, ensuring it can handle real-time decision-making efficiently and with minimal overhead.\n\n2. **Simple Interface**: This library is designed to be easy to use, with a simple interface that allows you to define actions and goals with minimal code.\n\n3. **Supports Various State Types**: With support for both numeric and symbolic states, this library can be applied to a wide range of problems and use cases. This allows you to define states such as `food=10` or `!food` (no food).\n\n4. **A\\* Search**: Utilizing the A\\* algorithm, the library efficiently navigates through possible plans, aiding in finding optimal paths to achieve goals. It uses the state distance heuristic to determine the best plan.\n\nGOAP's blend of efficiency, flexibility, and practical search capabilities makes it a valuable tool for developers looking to incorporate advanced planning and decision-making into their AI applications.\n\n## Quick Start\n\nThis guide will walk you through implementing a simple AI using the GOAP (Goal-Oriented Action Planning) library. We'll create a scenario where an AI character must manage hunger and tiredness while gathering food. Our AI character starts with high hunger and no food. The goal is to accumulate food (`food\u003e80`) while managing hunger and tiredness.\n\n### Step 1: Initialize States\n\nStart by defining the initial state (`init`) and the goal (`goal`):\n\n```go\ninit := goap.StateOf(\"hunger=80\", \"!food\", \"!tired\")\ngoal := goap.StateOf(\"food\u003e80\")\n```\n\n- `init` represents the AI's starting condition: hunger at 80, no food, and not tired.\n- `goal` is the desired state where the AI has more than 80 units of food.\n\n### Step 2: Define Actions\n\nDefine the actions the AI can perform: `eat`, `forage`, and `sleep`. Each action has prerequisites and outcomes. First, we need to implement the `Action` interface. For simplicity, we create a generic action:\n\n```go\n// NewAction creates a new action from the given name, require and outcome.\nfunc NewAction(name, require, outcome string) *Action {\n\treturn \u0026Action{\n\t\tname:    name,\n\t\trequire: goap.StateOf(strings.Split(require, \",\")...),\n\t\toutcome: goap.StateOf(strings.Split(outcome, \",\")...),\n\t}\n}\n\n// Action represents a single action that can be performed by the agent.\ntype Action struct {\n\tname    string\n\tcost    int\n\trequire *goap.State\n\toutcome *goap.State\n}\n\n// Simulate simulates the action and returns the required and outcome states.\nfunc (a *Action) Simulate(current *goap.State) (*goap.State, *goap.State) {\n\treturn a.require, a.outcome\n}\n\n// Cost returns the cost of the action.\nfunc (a *Action) Cost() float32 {\n\treturn 1\n}\n```\n\nNext, we can define a list of actions that the AI can perform (`eat`, `forage`, and `sleep`).\n\n```go\nactions := []goap.Action{\n    NewAction(\"eat\", \"food\u003e0\", \"hunger-50,food-5\"),\n    NewAction(\"forage\", \"tired\u003c50\", \"tired+20,food+10,hunger+5\"),\n    NewAction(\"sleep\", \"tired\u003e30\", \"tired-30\"),\n}\n```\n\n- `eat`: Can be performed if `food\u003e0`. Reduces hunger by 50 and food by 5.\n- `forage`: Possible when `tired\u003c50`. Increases tiredness by 20, food by 10, and hunger by 5.\n- `sleep`: Executable if `tired\u003e30`. Reduces tiredness by 30.\n\n### Step 3: Generate the Plan\n\nGenerate a plan to reach the goal from the initial state using the defined actions.\n\n```go\nplan, err := goap.Plan(init, goal, actions)\nif err != nil {\n    panic(err)\n}\n```\n\nThe output will be a sequence of actions that the AI character needs to perform to achieve its goal. Here's an example:\n\n```text\n1. forage\n2. forage\n3. forage\n4. sleep\n5. forage\n6. sleep\n7. forage\n8. forage\n9. sleep\n10. forage\n11. sleep\n12. forage\n13. eat\n14. forage\n```\n\nThis sequence represents the AI's decision-making process, balancing foraging for food, eating to reduce hunger, and sleeping to manage tiredness.\n\n## License\n\nThis library is licensed under the MIT license. See the [LICENSE](https://github.com/kelindar/goap/LICENSE) file in the project root for more details.\n\n## Credits\n\nThis library is developed and maintained by [Roman Atachiants](https://github.com/kelindar) and contributions from the open-source community. We welcome contributions and feedback to make the library even better.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelindar%2Fgoap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelindar%2Fgoap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelindar%2Fgoap/lists"}