Code Monkey home page Code Monkey logo

regoap's People

Contributors

evancorl avatar luxkun avatar scribblerockerz avatar shanecelis avatar tmpxyz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

regoap's Issues

Some Rookie questions about it

Hi
I am trying to use regoap to implement AI.
My example is : my bot is doing patrol until he found his enemy.
I have findAction
so the precondition: isFindEnemy: false; canMove: true;
effect: isFindEnemy: true;

My Question is that where is the best place in findAction I should implement patrol code?

Thanks

Problem in AStar

I'm using AStar.cs in a path finder. There was a problem that nodes that should have been on the path where lost. The problem was fixed by changing the break statement at line 76 to continue. I believe break here is a mistake.

Kind regards
PLux

"Possible goal warning" complication

Every goal warn if it possible but not active, but by inheriting from ReGoapGoal you have

public virtual bool IsGoalPossible() { return true; }

so every goal will try to interupt current action even if this goal cant be reached atm.

I added "warnPossible" flag to ReGoapGoal which false by default. Elseway you should override IsGoalPossible() and add significant conditions.

Fatal error when debug set full

LogLevel - Full

ToString can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
System.String:Format(String, Object, Object)
ReGoap.Unity.ReGoapAction2:ToString(GoapActionStackData2) (at Assets/!Project/ReGoap/Unity/ReGoapAction.cs:138)
ReGoap.Planner.ReGoapPlanner2:Plan(IReGoapAgent2, IReGoapGoal2, Queue1, Action1) (at Assets/!Project/ReGoap/Planner/ReGoapPlanner.cs:124) ReGoap.Unity.ReGoapPlannerThread2:CheckWorkers() (at Assets/!Project/ReGoap/Unity/ReGoapPlannerManager.cs:48)
ReGoap.Unity.ReGoapPlannerThread`2:MainLoop() (at Assets/!Project/ReGoap/Unity/ReGoapPlannerManager.cs:33)

example doesn't work when minion is duplicated

multipleresourcecensor.cs struggles when the minion gets duplicated n times, something to do with the cacheupdatedelays
as I understand it, this variable's purpose is to avoid spamming by multiple agent, like a lock, I suggest moving it to the resource itself and have the lock mechanism as part of resource query, this way, naturally 1000 agents will show politeness towards the trees

Need of more documentation on Actions

Hey,

I just started using your library. Loved the Debug view and the sensors implementation.
I wanted to try out my first implementation of performing a waypoint follow. Decided to set Goal as Patrol and Actions were to be designed accordingly.
I went though the doc it looked simple. But the example got me quite confused.
in the FSM-Example Take GenericGoToAction.cs

The calss has something called IReGoapActionSettings<string, object>

public override IReGoapActionSettings<string, object> GetSettings(IReGoapAgent<string, object> goapAgent, ReGoapState<string, object> goalState)
    {
        settings = new GenericGoToSettings
        {
            ObjectivePosition = GetWantedPositionFromState(goalState)
        };
        return base.GetSettings(goapAgent, goalState);
    }

  public override ReGoapState<string, object> GetEffects(ReGoapState<string, object> goalState, IReGoapAction<string, object> next = null)
    {
        var goalWantedPosition = GetWantedPositionFromState(goalState);
        if (goalWantedPosition.HasValue)
        {
            effects.Set("isAtPosition", goalWantedPosition);
        }
        else
        {
            SetDefaultEffects();
        }
        return base.GetEffects(goalState, next);
    }

And these two Blocks of code just confused me. Could you caret o explain why are we overriding GetEffects and whats basically happening here

And could be kind enough to add a little more details on Actions in ReGOAP

Thanks

Potential multi-threading issue?

Hey!

I have been messing around with ReGoap for a couple of days and feel like I am getting a hang of it. I have run into a weird issue thought that I can't seem to figure out/fix. When I have the ReGoap planner set to 2-4 threads and have multiple AI agents within the scene some agents will act upon their actions while some don't do anything at all. I then restart the scene and sometimes none of them work and sometimes all of them work. What makes me think it's a multithreading issue is that when I set the thread count to 1 the agents work all the time every time. Something you may want to check out if you got time. If I had a better understanding of multithreading I would look into more myself but alas I am a scrub.

Add more things to FSMExample

FSMExample should have more agents (WeaponsBuilder, Defender, EnemyAgent?) and all the relatives goals/actions needed for them.

Should not be something too complex but it is needed so users can have some different behaviours to use in their games.

Can only carry out a goal if it's goal isn't in the world state

I'm creating a colony sim where agents should be able to repeatedly do a certain goal if it's possible regardless of whether it has been done before. I'm not using Unity but I'm using modified versions of the unity example scripts. Is there any way to make this work? The library is pretty complicated with a lot of moving parts and took me a few hours to figure out what was going on here. Is there a planner setting somewhere to allow an action to take place where its effects are already in the world state?

Thoughts on pooling/sharing actions?

I am tinkering with using ReGoap in situations where there is a plurality of actions that may satisfy a goal, which is different from the simplistic approach that the included example used(singleton resource managers, etc). The reason being is that I want to try and use the planner to create a good solution using some spatial considerations as well, which is not something the example does. Naturally this can create quite a number of action instances. Have you considered or thought about setting the actions up in a more dynamic or poolable manner, where the actions can be considered more globally available for any number of agents, rather than each agent having copies of them?

To get an idea what I'm shooting for, consider if the GoapTest example that is included allocated an action per instance of a tree resource, bank resource, workstation resource, etc, with conditions based on it's spatial location. The idea here is that provided the GoTo actions estimated their cost based on distance or travel time, the overall plan should represent the most efficient set of actions to perform based on travel time as well as just fixed action costs.

Seems GOAP isn't used that often in this manner, but I wanted to get your thoughts on the feasibility of globalizing a set of the actions rather than having to clone potentially dozens per agent.

Alternately, if you have a reasonable way to configure the conditions through the planner that might avoid the need to have an action per in-world resource and still get reasonable spatial considerations, I'm interested in that too.

Thanks

Compiler error after import to unity

2017.4.1f1

The type or namespace name CompilerErrorCollection' does not exist in the namespace System.CodeDom.Compiler'. Are you missing an assembly reference?

Compile Error - Unity 2020.2.1f1

ReGoapNodeBaseEditor.cs contains a reference to UnityEngine.VR which is no longer a valid namespace. Removing the using reference fixes the issue and the project compiles and runs.

More flexible condition comparisons

There seems to be a predicate in the code that might be intended for something along these lines, but it doesn't seem to be exposed to the actions at all.

Something like
preconditions.Set("hasLog", 10, predicateGreaterOrEqual);

Perhaps that last parameter takes an IComparer or just a Func like you have the current predicate defined as, and if excluded it is treated as a strict equality comparison.

The overall point is to allow more than equality comparison based action conditions, which are essential for gatherer/builder type planning where many types and quantities of resources might be necessary to complete a task.

Bug in Node Expansion during AStar search?

In ReGoapNode.cs, there seems to be a bug on line 149 in the Expand method.
The line:
!goal.HasAnyConflict(precond) seems to be an error.

Any action that has a precondition that's different than the goal will always be rejected. Consider the case where the goal GoSwimming requires { isAtPosition: 0} and a JumpIntoWater action with effect {isAtPosition: 0} and a precondition {isAtPosition: 1}.
The action precondition will always be in conflict (as it should be) with the goal and therefore never be chosen for the expandList.

Bug? Or am I misunderstanding something?

----- Ed

Improve Action Cost calculation

Currently the "next" action doesn't appear to be getting passed to the GetCost function.

Related to this, I'm trying to think through the requirements for having the information necessary to accurately estimate travel times into the cost of an action. Essentially the action needs to know the start and end positions that the actions is attempting to cover for cost purposes.

Correct me if I'm wrong, but given that it is a backwards search, I think the goalState passed into GetCost will have the destination, including any intra-plan moves in the form of isAtPosition/isAtTransform conditions, so the move action should be able to pull out those values with GetObjective as the examples do.

As for the "start", given that it is a backwards search, that will always be the agent current position correct? (alternately a forward search would have to pass positional estimates through the world state each step of the plan I think)

How does GenericGoToAction know where to go?

Hi,

I've been trying to understand how to implement my own actions, mostly moving and picking up things, but I don't understand how GenericGoToAction knows where to go.

Both "objectivePosition" and "isAtPosition" are only set from within the action and "startPosition" is only set from PositionSensor which is on the same object. Also, why is "startPosition" updated with the agent's current position, seems like a confusing name when used like that.

I would greatly appreciate any insight of how this example works so use this asset for real ๐Ÿ’ฏ

Some question about multiple goals

Hello.
I am using ReGoap and Im wish to thank you for this work!
But there are some strange thing for me. When i add multiple goals(simpleones: "go to marker" and "shoot at enemy" for example), planner choose top priority goal and agent execute it. But after planer still try to execute same goal by running 0 actions plan.
There are some issue? Or i should procedurally change goals priorietes when some goal achieved?
Thanks
regoapconsole

How can you re-evaluate goals?

I have a goal that has the requirement of "killPlayer", which moves an enemy towards the player and once we are close enough, fires off a shoot player action which has the effect "killPlayer". Now, the player doesn't die most of the time so I basically want this goal re-ran (get player, move towards player, shoot player OR if close enough, just shoot player), how can I do this? Or if this is not the proper way to get this behavior, what am I missing?

Thanks in advance

Example of a FPS/Soul-like

Since many library users are asking on how to use this library ona FPS/Soul-like game (where the main agent search for enemies/players and try to kill them) an example about such a game is needed,

Why you need FSM?

Thanks for great framework!
Can you describe more detailed why you add FSM to example?
How FSM can be used and helps?

Aren't sensors extremely inefficient?

So I was having a chat with some guys on discord who implemented their own GOAP system within their game and we got on the topic of sensors. They believed that sensors were inefficient because they are constantly running and doing whatever logic they need to all the time. If I have multiple sensors on one GO, each used for a specific action that don't seem to turn off when they shouldn't be in use, isn't that a huge performance hit?

This is a question and should be labeled as such, but I don't know how to do that ๐Ÿ˜„

A Planning bug

The planner seems to have a bug here.

Here's a unit-test to reproduce it.

  • The one goal is "prepareFoodAndMoney"
  • Action "MineOre" would set hasMoney = true;
  • Action "BuyFood" would set hasMoney = false, hasFood = true;

So the expected plan is like MineOre -> BuyFood -> MineOre;
However the planner can only create plan like MineOre -> BuyFood;

        public void TestPlan2(IGoapPlanner<string, object> planner)
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "Mine Ore",
                new Dictionary<string, object> { },
                new Dictionary<string, object> { { "hasMoney", true } }, 10);
            ReGoapTestsHelper.GetCustomAction(gameObject, "Buy Food",
                new Dictionary<string, object> { { "hasMoney", true } },
                new Dictionary<string, object> { { "hasFood", true }, { "hasMoney", false } }, 2);

            var theGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "PrepareFoodAndMoney",
                new Dictionary<string, object> { { "hasMoney", true }, { "hasFood", true } });

            var memory = gameObject.AddComponent<ReGoapTestMemory>();
            memory.Init();

            var agent = gameObject.AddComponent<ReGoapTestAgent>();
            agent.Init();

            var plan = planner.Plan(agent, null, null, null);

            Assert.That(plan, Is.EqualTo(theGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
TestPlan2 (0.067s)
---
Expected: True
  But was:  False
---
at ReGoap.Unity.Editor.Test.ReGoapTestsHelper.ApplyAndValidatePlan (IReGoapGoal`2 plan, ReGoap.Unity.Test.ReGoapTestMemory memory) [0x000d7] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTestsHelper.cs:55
at ReGoap.Unity.Editor.Test.ReGoapTests.TestPlan2 (IGoapPlanner`2 planner) [0x000ef] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTests.cs:72
at ReGoap.Unity.Editor.Test.ReGoapTests.TestPlan2 () [0x00008] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTests.cs:45
---
[ReGoalPlanner] Starting planning calculation for agent: GoapAgent('')
[Astar] Success iterations: 4
[ReGoapPlanner] Calculated plan for goal 'GoapGoal('PrepareFoodAndMoney')', plan length: 2
[ReGoapPlanner] 0) GoapAction('Mine Ore')
[ReGoapPlanner] 1) GoapAction('Buy Food')

Another Planning bug

The planner might make wrong plan on some special conditions.
Here's a unit-test to reproduce it.

The one goal is "GatherAppleAndPeach"

  • Action "GatherApple" precond: { At : "Farm"} effects : { hasApple = true };
  • Action "GatherPeach" precond: { At : "Farm" } effects: {hasPeach = true };
  • Action "Goto" effects: {At: Farm}

With special cost setting, the planner might give wrong plan with steps:

  1. GatherPeach
  2. Goto
  3. GatherApple
        [Test]
        public void TestGatherGotoGather()
        {
            var gameObject = new GameObject();

            ReGoapTestsHelper.GetCustomAction(gameObject, "GatherApple",
                new Dictionary<string, object> { { "At", "Farm" } },
                new Dictionary<string, object> { { "hasApple", true } }, 1);
            ReGoapTestsHelper.GetCustomAction(gameObject, "GatherPeach",
                new Dictionary<string, object> { { "At", "Farm" } },
                new Dictionary<string, object> { { "hasPeach", true } }, 2);
            ReGoapTestsHelper.GetCustomAction(gameObject, "Goto",
                new Dictionary<string, object> { },
                new Dictionary<string, object> { { "At", "Farm" } }, 10);

            var theGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "GatherAll",
                new Dictionary<string, object> { { "hasApple", true }, { "hasPeach", true } });

            var memory = gameObject.AddComponent<ReGoapTestMemory>();
            memory.Init();

            var agent = gameObject.AddComponent<ReGoapTestAgent>();
            agent.Init();

            var plan = GetPlanner().Plan(agent, null, null, null);

            Assert.That(plan, Is.EqualTo(theGoal));
            // validate plan actions
            ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
        }
TestGatherGotoGather (0.051s)
---
Expected: True
  But was:  False
---
at ReGoap.Unity.Editor.Test.ReGoapTestsHelper.ApplyAndValidatePlan (ReGoap.Core.IReGoapGoal`2[T,W] plan, ReGoap.Unity.Test.ReGoapTestMemory memory) [0x0003d] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTestsHelper.cs:48
at ReGoap.Unity.Editor.Test.ReGoapTests.TestGatherGotoGather () [0x0011d] in E:\works\programs\GameProjects\TestGround\TestReGOAP\Assets\ReGoap\Unity\Editor\Test\ReGoapTests.cs:70
---
[ReGoalPlanner] Starting planning calculation for agent: GoapAgent('')
[Astar] Success iterations: 9
[ReGoapPlanner] Calculated plan for goal 'GoapGoal('GatherAll')', plan length: 3
[ReGoapPlanner] 0) GoapAction('GatherPeach')
[ReGoapPlanner] 1) GoapAction('Goto')
[ReGoapPlanner] 2) GoapAction('GatherApple')

Here is a plan making graph made with graphviz;
debug

Handling Multiple Goals, and Re-Evaluating Goals at Runtime?

Hey there,

Could you provide some insight into how you'd go about:

  • Managing multiple goals. E.g. Builder will normally work, but if user clicks somewhere the builder will first go "investigate" the clicked position, before going back to work.
  • Interrupting or forcing re-evaluating a plan. I feel like I'm missing a core GOAP concept here. Example use case, we spawn the builders, give them an "Investigate" goal, but then we want to change the target of the Investigate goal. Currently it seems the planner never re-plans properly.

If you can provide these answers, I'd love to update the example scene and submit a pull request. I have a couple other things I've done relating to root motion based locomotion (what I'm calling motors) that could be a good addition too.

example bug

primitiveresource.cs doesn't shrink the resource as intended so it should be:

`using UnityEngine;
using System.Collections;

public class PrimitiveResource : Resource
{
public float MinScalePercentage = 0.1f;
private Vector3 startingScale;

protected override void Awake ()
{
base.Awake ();
startingScale = transform.localScale;
}

public override void RemoveResource(float value)
{
base.RemoveResource(value);
transform.localScale = startingScale * (MinScalePercentage + (1f - MinScalePercentage) * (Capacity/startingCapacity)); // scale down based on capacity
}
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.