AI 툴킷은 게임 NPC의 두뇌를 구축하기위한 도구를 제공하는 헤더 전용 C ++ 라이브러리입니다.
그것은 제공합니다 :
왜이 프로젝트인가? 글쎄, 나는 그것에 대해 썼다.
이 저장소의 include
폴더를 포함 경로에 추가하십시오.
또는 하위 모듈로 추가하십시오.
$ git submodule add https://github.com/linkdd/aitoolkit.git
$ g++ -std=c++23 -Iaitoolkit/include main.cpp -o mygame
NB : 이 라이브러리는 C ++ 20과 호환됩니다.
또는 Shipp을 사용하여 종속성에 추가하십시오.
{
"name" : " myproject " ,
"version" : " 0.1.0 " ,
"dependencies" : [
{
"name" : " aitoolkit " ,
"url" : " https://github.com/linkdd/aitoolkit.git " ,
"version" : " v0.5.1 "
}
]
}
먼저 헤더 포함 :
# include < aitoolkit/fsm.hpp >
using namespace aitoolkit ::fsm ;
그런 다음 칠판 유형을 만듭니다.
struct blackboard_type {
// ...
};
그런 다음 각 주에 대한 상태 유형을 만듭니다.
class state_dummy final : public state<blackboard_type> {
public:
virtual void enter (blackboard_type& blackboard) override {
// ...
}
virtual void exit (blackboard_type& blackboard) override {
// ...
}
virtual void pause (blackboard_type& blackboard) override {
// ...
}
virtual void resume (blackboard_type& blackboard) override {
// ...
}
virtual void update (blackboard_type& blackboard) override {
// ...
}
};
간단한 상태 기계 만들기 :
auto simple_bb = blackboard_type{};
auto simple_fsm = simple_machine<blackboard_type>();
simple_fsm.set_state(state_dummy{}, simple_bb);
simple_fsm.pause(simple_bb);
simple_fsm.resume(simple_bb);
simple_fsm.update(simple_bb);
또는 스택 상태 머신으로 :
auto stack_bb = blackboard_type{};
auto stack_fsm = stack_machine<blackboard_type>{};
stack_fsm.push_state(state_dummy{}, stack_bb);
stack_fsm.push_state(state_dummy{}, stack_bb);
stack_fsm.update(stack_bb);
stack_fsm.pop_state(stack_bb);
stack_fsm.pop_state(stack_bb);
먼저 헤더 포함 :
# include < aitoolkit/behtree.hpp >
using namespace aitoolkit ::bt ;
그런 다음 칠판 유형을 만듭니다.
struct blackboard_type {
// ...
};
그런 다음 나무를 만드십시오.
auto tree = seq<blackboard_type>(
node_list<blackboard_type>(
check<blackboard_type>([]( const blackboard_type& bb) {
// check some condition
return true ;
}),
task<blackboard_type>([](blackboard_type& bb) {
// perform some action
return execution_state::success;
})
)
);
마지막으로 평가하십시오.
auto blackboard = blackboard_type{
// ...
};
auto state = tree.evaluate(blackboard);
For more informations, consult the documentation.
First, include the header file:
# include < aitoolkit/utility.hpp >
using namespace aitoolkit ::utility ;
Then, create a blackboard type:
struct blackboard_type {
int food{ 0 };
int wood{ 0 };
int stone{ 0 };
int gold{ 0 };
};
다음으로 수행 할 수있는 각 조치에 대한 클래스를 만듭니다.
class collect_food final : public action<blackboard_type> {
public:
virtual float score ( const blackboard_type& blackboard) const override {
return 50 . 0f ;
}
virtual void apply (blackboard_type& blackboard) const override {
blackboard. food += 1 ;
}
};
class collect_wood final : public action<blackboard_type> {
public:
virtual float score ( const blackboard_type& blackboard) const override {
return 150 . 0f ;
}
virtual void apply (blackboard_type& blackboard) const override {
blackboard. wood += 1 ;
}
};
class collect_stone final : public action<blackboard_type> {
public:
virtual float score ( const blackboard_type& blackboard) const override {
return - 10 . 0f ;
}
virtual void apply (blackboard_type& blackboard) const override {
blackboard. stone += 1 ;
}
};
class collect_gold final : public action<blackboard_type> {
public:
virtual float score ( const blackboard_type& blackboard) const override {
return 75 . 0f ;
}
virtual void apply (blackboard_type& blackboard) const override {
blackboard. gold += 1 ;
}
};
마지막으로 평가자를 만들고 실행하십시오.
auto evaluator = evaluator<blackboard_type>(
action_list<blackboard_type>(
collect_food{},
collect_wood{},
collect_stone{},
collect_gold{}
)
);
auto blackboard = blackboard_type{};
evaluator.run(blackboard);
먼저 헤더 파일 포함 :
# include < aitoolkit/goap.hpp >
using namespace aitoolkit ::goap ;
그런 다음 플래너의 상태를 유지하는 칠판 클래스를 만듭니다.
struct blackboard_type {
bool has_axe{ false };
int wood{ 0 };
};
NB : 칠판은 비교할 수 있고 (
a == b
) 해시 가능해야합니다.
다음으로 수행 할 수있는 각 조치에 대한 클래스를 만듭니다.
class get_axe final : public action<blackboard_type> {
public:
virtual float cost ( const blackboard_type& blackboard) const override {
return 1 . 0f ;
}
virtual bool check_preconditions ( const blackboard_type& blackboard) const override {
return !blackboard. has_axe ;
}
virtual void apply_effects (blackboard_type& blackboard, bool dry_run) const override {
blackboard. has_axe = true ;
}
};
class chop_tree final : public action<blackboard_type> {
public:
virtual float cost ( const blackboard_type& blackboard) const override {
return 1 . 0f ;
}
virtual bool check_preconditions ( const blackboard_type& blackboard) const override {
return blackboard. has_axe ;
}
virtual void apply_effects (blackboard_type& blackboard, bool dry_run) const override {
blackboard. wood += 1 ;
}
};
마지막으로 계획을 세우고 실행하십시오.
auto initial = blackboard_type{};
auto goal = blackboard_type{
. has_axe = true ,
. wood = 3
};
auto p = planner<blackboard_type>(
action_list<blackboard_type>(
get_axe{},
chop_tree{}
),
initial,
goal
);
auto blackboard = initial;
while (p) {
p. run_next (blackboard); // will mutate the blackboard
}
자세한 정보는 문서를 참조하십시오.
문서는 여기에서 온라인으로 제공됩니다.
Doxygen을 사용하여 로컬로 만들 수 있습니다.
$ make docs
이 라이브러리는 MIT 라이센스의 조건에 따라 릴리스됩니다.