-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_behavior_tree.cpp
More file actions
95 lines (72 loc) · 1.85 KB
/
Copy pathtest_behavior_tree.cpp
File metadata and controls
95 lines (72 loc) · 1.85 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// test_behavior_tree.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <Windows.h>
#include "pw_behavior_tree.h"
#include "pw_behavior_board.h"
#include "pw_behavior_selector.h"
#include "pw_behavior_decorator.h"
#include "pw_behavior_sequence.h"
#include "pw_behavior_condition.h"
#include "pw_behavior_action.h"
#include <iostream>
#include <time.h>
using namespace pwngs;
class TestActionNode : public pwngs::BehaviorAction
{
public:
TestActionNode(const char* text)
{
mText = text;
}
virtual EBehaviorResult Execute(BehaviorEnvriment& env)
{
std::cout << "TestActionNode Evaluation:" << mText << std::endl;
return BEHAVIOR_RESULT_FINISHED;
}
private:
std::string mText;
};
int _tmain(int argc, _TCHAR* argv[])
{
BehaviorBoard board;
BehaviorCharacter main;
BehaviorEnvriment env;
BehaviorTree tree;
env.board = &board;
env.main = &main;
int count = 1;
BehaviorVariable* v1 = new BehaviorVariableConst<double>(3221.121213f);
BehaviorVariable* v2 = new BehaviorVariableConst<double>(3221.121213f);
assert(v1->Equal(v2));
delete v1;
delete v2;
// env.board->AddVariable("count",new BehaviorVariableConst<int32>(10));
BehaviorVariable* varCount = env.board->AddVariable("count",new BehaviorVariablePointer<int32>(&count));
srand(time(NULL));
BehaviorNode* node = (new BehaviorDecoratorRepeatAlways())->InsertNodes
(
(new BehaviorDecoratorIf())->InsertNodes
(
(new BehaviorDecoratorNot())->InsertNodes
(
(new BehaviorCondition()),
NULL
),
new TestActionNode("began"),
NULL
),
(new BehaviorDecoratorWait(3000))->InsertNodes
(
new TestActionNode("action"),
NULL
),
new TestActionNode("ended"),
NULL
);
tree.SetStateNode(0,node);
int result = tree.Evaluation(env);
while(result == BEHAVIOR_RESULT_RUNNING)
result = tree.Evaluation(env);
return 0;
}