-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.py
More file actions
47 lines (42 loc) · 1.15 KB
/
Copy pathnode.py
File metadata and controls
47 lines (42 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class NodeType:
ACTION = 1
CONDITION = 2
ACTION_CONDITION = 3
PRIORITY = 4
SEQUENCE = 5
PARALLEL = 6
@staticmethod
def str(nodeType):
return [
"ACTION",
"CONDITION",
"ACTION_CONDITION",
"PRIORITY",
"SEQUENCE",
"PARALLEL"
][nodeType-1]
class Node:
"""
BehaviorTree node
parnet - Node or None
children - Nodes or []
type - NodeType
"""
def __init__(self, type_, children=[], parent=None, action=None, parallelSuccessCount=None):
if type_ is None:
raise AttributeError("Must set type in Node")
self.type = type_
self.parent = parent
self.children = children
self.action = action
self.parallelSuccessCount = parallelSuccessCount
def __str__(self):
if self.type in [NodeType.ACTION, NodeType.CONDITION, NodeType.ACTION_CONDITION]:
selfstr = "{}({})".format(NodeType.str(self.type), self.action)
else:
selfstr = NodeType.str(self.type)
return "[{}:{}:{}]".format(
selfstr,
NodeType.str(self.parent.type) if self.parent is not None else "_",
len(self.children)
)