{"id":28919382,"url":"https://github.com/derekgooding/goaphero","last_synced_at":"2026-03-03T16:09:46.805Z","repository":{"id":292215243,"uuid":"980130232","full_name":"DerekGooding/GOAPHero","owner":"DerekGooding","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-08T20:38:34.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-05T01:15:52.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","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/DerekGooding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-08T15:59:32.000Z","updated_at":"2025-05-08T20:38:37.000Z","dependencies_parsed_at":"2025-05-08T18:37:41.068Z","dependency_job_id":"d6f3aad5-585a-4491-964a-2e15def217ed","html_url":"https://github.com/DerekGooding/GOAPHero","commit_stats":null,"previous_names":["derekgooding/goaphero"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DerekGooding/GOAPHero","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekGooding%2FGOAPHero","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekGooding%2FGOAPHero/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekGooding%2FGOAPHero/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekGooding%2FGOAPHero/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DerekGooding","download_url":"https://codeload.github.com/DerekGooding/GOAPHero/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DerekGooding%2FGOAPHero/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30051208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T15:26:47.567Z","status":"ssl_error","status_checked_at":"2026-03-03T15:26:17.132Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-06-22T03:06:40.397Z","updated_at":"2026-03-03T16:09:46.800Z","avatar_url":"https://github.com/DerekGooding.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GOAP Planning System Design\n\n## Overview\n\nThe Goal-Oriented Action Planning (GOAP) system is designed to enable autonomous agents to make intelligent decisions based on dynamic environmental data and internal state. The architecture is modular and layered, providing separation of concerns across sensing, reasoning, and execution. This document outlines the system's core layers, responsibilities, interconnections, and includes example C# implementations.\n\n## Layered Architecture\n\n### 1. Sensor Layer\n\nThe Sensor Layer is responsible for perceiving the environment and internal state of the agent. Each sensor component operates independently and returns structured data relevant to its domain.\n\n**Sensors:**\n\n* **VisionSensor:** Detects visible objects and their positions.\n* **HearingSensor:** Detects sound-emitting objects and estimates proximity.\n* **SmellSensor:** Detects odor-emitting objects with estimated intensity.\n* **InventorySensor:** Returns the current list of items and quantities held.\n* **StatsSensor:** Reports personal statistics such as health, stamina, and hunger.\n* **MemorySensor:** Retrieves remembered events or facts from previous encounters.\n\n**Output:** Lists of detected objects, positions, quantities, and statistical values.\n\n**Example:**\n\n```csharp\npublic interface ISensor\u003cT\u003e\n{\n    T Sense();\n}\n\npublic class InventorySensor : ISensor\u003cList\u003c(Item item, int quantity)\u003e\u003e\n{\n    private readonly Inventory _inventory;\n\n    public InventorySensor(Inventory inventory)\n    {\n        _inventory = inventory;\n    }\n\n    public List\u003c(Item, int)\u003e Sense()\n    {\n        return _inventory.Items.ToList();\n    }\n}\n```\n\n### 2. List Aggregation Layer\n\nThis layer aggregates and normalizes outputs from the Sensor Layer into a unified perception context. The goal is to centralize environmental and internal data to facilitate subsequent logical evaluations.\n\n**Responsibilities:**\n\n* Combine data from all sensors.\n* Provide queryable access to the complete perception context.\n* Maintain temporal relevance by purging outdated or stale information.\n\n**Example:**\n\n```csharp\npublic class PerceptionContext\n{\n    public List\u003c(Item item, int quantity)\u003e InventoryItems { get; set; } = [];\n    public Dictionary\u003cStatType, float\u003e Stats { get; set; } = [];\n    public List\u003cGameObject\u003e VisibleObjects { get; set; } = [];\n    // Additional perception data as needed\n}\n```\n\n### 3. Checklist Layer\n\nThe Checklist Layer derives boolean world-state facts from the aggregated sensor data. Each checklist item encapsulates a logical evaluation that returns true or false based on current perception context.\n\n**Checklist Evaluations:**\n\n* Defined by logical predicates.\n* Evaluate presence, quantity, or proximity of specific objects.\n* May reference personal statistics or memory components.\n\n**Output:**\nA dictionary of condition keys mapped to boolean values, representing the agent's current world state.\n\n**Example:**\n\n```csharp\npublic class ChecklistCondition\n{\n    public string Key { get; init; }\n    public Func\u003cPerceptionContext, bool\u003e Evaluate { get; init; }\n}\n\nvar hasFood = new ChecklistCondition\n{\n    Key = \"HasFood\",\n    Evaluate = ctx =\u003e ctx.InventoryItems.Any(i =\u003e i.item.Type == ItemType.Food \u0026\u0026 i.quantity \u003e 0)\n};\n```\n\n### 4. Planning Layer\n\nThis layer implements the core GOAP algorithm. It evaluates available actions against the current world state and identifies a viable sequence of actions that achieve a specified goal state.\n\n**Key Elements:**\n\n* **Action Definitions:** Include preconditions and effects represented as boolean dictionaries.\n* **Goal Conditions:** Target world-state conditions the agent aims to satisfy.\n* **Planner:** Searches for action sequences that transform the current world state into the goal state by satisfying all preconditions and applying effects iteratively.\n\n**Example:**\n\n```csharp\npublic class GoapAction\n{\n    public string Name { get; init; }\n    public Dictionary\u003cstring, bool\u003e Preconditions { get; init; } = [];\n    public Dictionary\u003cstring, bool\u003e Effects { get; init; } = [];\n    public Func\u003cbool\u003e CanExecute { get; init; }\n    public Action Execute { get; init; }\n}\n\npublic class GoapPlanner\n{\n    public List\u003cGoapAction\u003e Plan(\n        Dictionary\u003cstring, bool\u003e currentState,\n        Dictionary\u003cstring, bool\u003e goal,\n        List\u003cGoapAction\u003e availableActions)\n    {\n        // Simplified forward planner\n        var plan = new List\u003cGoapAction\u003e();\n        var state = new Dictionary\u003cstring, bool\u003e(currentState);\n\n        foreach (var action in availableActions)\n        {\n            if (action.Preconditions.All(p =\u003e state.TryGetValue(p.Key, out var val) \u0026\u0026 val == p.Value))\n            {\n                plan.Add(action);\n                foreach (var effect in action.Effects)\n                {\n                    state[effect.Key] = effect.Value;\n                }\n\n                if (goal.All(g =\u003e state.TryGetValue(g.Key, out var val) \u0026\u0026 val == g.Value))\n                {\n                    return plan;\n                }\n            }\n        }\n\n        return [];\n    }\n}\n```\n\n### 5. Action Execution Layer\n\nEach action has two functional aspects: a planning definition and an execution implementation.\n\n* **Planning Phase:** Specifies what conditions the action satisfies.\n* **Execution Phase:** Contains the real-world effect logic (e.g., modifying inventory, interacting with environment).\n\n**Example:**\n\n```csharp\nvar huntAction = new GoapAction\n{\n    Name = \"Hunt\",\n    Preconditions = new() { { \"HasWeapon\", true } },\n    Effects = new() { { \"HasFood\", true } },\n    CanExecute = () =\u003e true, // Replace with real condition check\n    Execute = () =\u003e Debug.Log(\"Agent goes hunting.\")\n};\n```\n\n### 6. Agent State Machine\n\nThe agent operates under an overarching finite state machine (FSM), which governs high-level behavior modes (e.g., idle, combat, survival). Each state is associated with specific checklist conditions and triggers that determine state transitions.\n\n**Responsibilities:**\n\n* Enable or disable specific checklist conditions.\n* Determine when replanning is necessary.\n* Handle transitions due to failures, timeouts, or external triggers.\n\n**Example:**\n\n```csharp\npublic enum AgentState\n{\n    Idle,\n    Combat,\n    Survival,\n    Fleeing\n}\n\npublic class AgentStateMachine\n{\n    public AgentState CurrentState { get; private set; } = AgentState.Idle;\n\n    public void UpdateState(Dictionary\u003cstring, bool\u003e worldState)\n    {\n        if (worldState.TryGetValue(\"IsThreatened\", out var threatened) \u0026\u0026 threatened)\n            CurrentState = AgentState.Combat;\n        else if (worldState.TryGetValue(\"NeedsFood\", out var hungry) \u0026\u0026 hungry)\n            CurrentState = AgentState.Survival;\n        else\n            CurrentState = AgentState.Idle;\n    }\n}\n```\n\n## Example Use Case: \"HasFood\" Condition\n\n1. **Sensor Layer:** InventorySensor detects an apple in inventory.\n2. **Checklist Layer:** The \"HasFood\" condition evaluates to true.\n3. **Planning Layer:** Goal to acquire food is skipped; already satisfied.\n4. **Execution:** No hunting actions are selected.\n5. **If False:** Planner selects the \"Hunt\" action to fulfill \"HasFood\".\n6. **Execution:** Upon success, the inventory is updated, re-evaluating \"HasFood\" as true.\n\n## Summary\n\nThis architecture provides a clean and extensible model for autonomous agent behavior. The separation between sensing, reasoning, and acting ensures maintainability and scalability in complex simulations. Each layer builds on the previous one, enabling nuanced decision-making rooted in both perception and internal goals. The included code snippets provide a basic framework that can be extended and refined based on the needs of your specific simulation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderekgooding%2Fgoaphero","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderekgooding%2Fgoaphero","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderekgooding%2Fgoaphero/lists"}