agoose77 / goap Goto Github PK
View Code? Open in Web Editor NEWA Python implementation of the Goal Oriented Action Planner.
A Python implementation of the Goal Oriented Action Planner.
from goap.action import Action
from goap.planner import Goal, Planner
from goap.director import Director
class BecomeTwo(Action):
effects = {"age": 2}
preconditions = {"age": 1}
class AgeGoal(Goal):
priority = 1.0
state = {"age": 2}
if __name__ == "__main__":
world_state = {"age": 1}
actions = [BecomeTwo()]
goals = [AgeGoal()]
planner = Planner(actions, world_state)
director = Director(planner, world_state, goals)
print("Initial State:", world_state)
plan = director.find_best_plan()
Initial State: {'age': 1}
Traceback (most recent call last):
File "debug-goap.py", line 27, in <module>
plan = director.find_best_plan()
File "/Users/tewhalen/Devel/GOAP-fork/goap/director.py", line 78, in find_best_plan
raise NoPlanFoundError("Couldn't find suitable plan")
goap.director.NoPlanFoundError: Couldn't find suitable plan
When multiple actions have the same pre-condition, the primary action has to precede the dependent actions. However, the current behavior seems to be that the primary action is placed arbitrarily in the plan step wherein some actions are placed ahead even if the pre-condition is not met.
In the following example, the expectation is that the action Action1
should be the first action in the plan because every other action has the precondition {"FIRST": True}
. However, that is not the result.
from action import Action
from planner import Planner
class Action1(Action):
effects = {"FIRST": True}
preconditions = {}
class Action2(Action):
effects = {"SECOND": True}
preconditions = {"FIRST": True}
class Action3(Action):
effects = {"THIRD": True}
preconditions = {"FIRST": True, "SECOND": True}
class Action4(Action):
effects = {"FOURTH": True}
preconditions = {"FIRST": True, "THIRD": True}
if __name__ == "__main__":
world_state = {"FIRST": False, "SECOND": False, "THIRD": False, "FOURTH": False}
goal_state = {"FOURTH": True}
print("Initial State:", world_state)
print("Goal State: ", goal_state)
actions = [Action1(), Action2(), Action3(), Action4()]
planner = Planner(world_state, actions)
plan = planner.find_plan(goal_state)
plan_str = 'PLAN:\n'
for ix, step in enumerate(plan):
plan_str += "....."*(ix+1) + str(step.action) + '\n'
print(plan_str)
Output plan steps:
PLAN:
.....Action2
..........Action3
...............Action1
....................Action4
Action2
is the first action; Its pre-condition {"FIRST": True}
is being ignored.
maybe you might want to apply this to a actor in game?
I have tools to record armature animations to Fcurves too.
When testing the newest changes i was encountering various typing issues throughout the project: "TypeError: 'type' object is not subscriptable"
I fixed this in my install by changing all typing occurrences of list and dict to their typing aliases List and Dict.
Is there a way to define not only a singular value per state variable but a list of values as precondition for an action? As far as I can see the ellipsis and reference() function pass the goal value to the precondition without further checking.
If it is not yet implemented, i would like to request this feature, as i think this makes the planner more versatile (and also helps with my problem setting ;) )
btw. I tried something like this for the preconditions of an action but it gets stuck in an infinite loop:
effects = {TOOL_STATE: None, BLOCK_IN_PLACE_STATE: ...}
preconditions = {
TOOL_STATE: reference(BLOCK_IN_PLACE_STATE) if reference(BLOCK_IN_PLACE_STATE) in CARRY_ABLE else ERROR_VAL,
BLOCK_IN_PLACE_STATE: None}
I just tested a simple setup with the newest changes. It seems that sometimes preconditions of actions are ignored. See the example below. You can switch the effects variable in the Place(Action) class to see the difference.
For some reason the planner skips Carry and directly selects Place if there is another state affected in the effects.
I will check further but didn't find the source of the problem yet.
from goap.action import Action
from goap.planner import RegressivePlanner
# see https://github.com/agoose77/GOAP
TOOL_STATE = "tool"
BLOCK_IN_PLACE_STATE = "block_in_place"
BLOCK_IN_STORAGE_STATE = "block_in_storage"
class Carry(Action):
effects = {TOOL_STATE: True, BLOCK_IN_STORAGE_STATE: False}
preconditions = {TOOL_STATE: False, BLOCK_IN_STORAGE_STATE: True}
class Place(Action):
# effects={BLOCK_IN_PLACE_STATE: True}
effects = {TOOL_STATE: False, BLOCK_IN_PLACE_STATE: True}
preconditions = {TOOL_STATE: True, BLOCK_IN_PLACE_STATE: False}
if __name__ == "__main__":
world_state = {TOOL_STATE: False, BLOCK_IN_PLACE_STATE: False, BLOCK_IN_STORAGE_STATE: True}
goal_state = {BLOCK_IN_PLACE_STATE: True}
print("Initial State:", world_state)
print("Goal State: ", goal_state)
actions = [Carry(), Place()]
planner = RegressivePlanner(actions)
plan = planner.find_plan(world_state, goal_state)
for p in plan:
print(p)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.