-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (64 loc) · 1.72 KB
/
main.cpp
File metadata and controls
73 lines (64 loc) · 1.72 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
//
// Created by draghan on 17.08.18.
//
#include "scripted_behavior_tree/ChaiScriptedBehaviorTree.hpp"
void evaluate_bt(BehaviorTree &bt);
int main()
{
// The main difference against regular
// BehaviorTree is that you have to provide
// a path to the script file in the constructor
// and then call load_tree() method, which could
// throw an exception.
// You have to be careful when evaluating an
// ChaiScriptedBehaviorTree - if there are bugs
// in script file, an exception will be thrown.
const std::string script_path{"./example.chai"};
ChaiScriptedBehaviorTree bt{script_path};
try
{
bt.load_tree();
std::cout << "#nodes: " << bt.get_node_count() << '\n';
bt.print(std::cout);
evaluate_bt(bt);
evaluate_bt(bt);
}
catch(std::exception &ex)
{
std::cerr << "Oooops, your's Chai is cold now. :<\n" << ex.what();
return 1;
}
}
void evaluate_bt(BehaviorTree &bt)
{
static size_t counter = 0;
// some printing...
std::cout << "----- " << counter++ << ". eval: \n";
// go back to root node wherever our tree actually is:
bt.set_at_absolutely();
auto tree_state = bt.evaluate();
// some more printing...
switch(tree_state)
{
case BehaviorState::undefined:
{
std::cout << "\nundefined\n";
break;
}
case BehaviorState::success:
{
std::cout << "\nsuccess\n";
break;
}
case BehaviorState::failure:
{
std::cout << "\nfailure\n";
break;
}
case BehaviorState::running:
{
std::cout << "\nrunning\n";
break;
}
}
}