AI Toolkit ist eine C ++-C ++ -Bibliothek nur für Header, die Tools zum Aufbau des Gehirns des NPCs Ihres Spiels bietet.
Es bietet:
Warum dieses Projekt? Nun, ich habe hier darüber geschrieben.
Fügen Sie den include
Ordner dieses Repositorys zu Ihren Einfügen hinzu.
Oder fügen Sie es als Submodul hinzu:
$ git submodule add https://github.com/linkdd/aitoolkit.git
$ g++ -std=c++23 -Iaitoolkit/include main.cpp -o mygame
NB: Diese Bibliothek ist mit C ++ 20 kompatibel.
Oder fügen Sie es mit Shipp zu Ihren Abhängigkeiten hinzu:
{
"name" : " myproject " ,
"version" : " 0.1.0 " ,
"dependencies" : [
{
"name" : " aitoolkit " ,
"url" : " https://github.com/linkdd/aitoolkit.git " ,
"version" : " v0.5.1 "
}
]
}
Geben Sie zunächst den Header ein:
# include < aitoolkit/fsm.hpp >
using namespace aitoolkit ::fsm ;
Erstellen Sie dann Ihren Blackboard -Typ:
struct blackboard_type {
// ...
};
Erstellen Sie dann einen Zustandstyp für jeden Ihrer Staaten:
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 {
// ...
}
};
Erstellen Sie Ihre einfache Zustandsmaschine:
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);
Oder mit einer Stack State -Maschine:
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);
Geben Sie zunächst den Header ein:
# include < aitoolkit/behtree.hpp >
using namespace aitoolkit ::bt ;
Erstellen Sie dann Ihren Blackboard -Typ:
struct blackboard_type {
// ...
};
Erstellen Sie dann Ihren Baum:
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;
})
)
);
Schließlich bewerten Sie es:
auto blackboard = blackboard_type{
// ...
};
auto state = tree.evaluate(blackboard);
Weitere Informationen finden Sie in der Dokumentation.
Geben Sie zunächst die Header -Datei an:
# include < aitoolkit/utility.hpp >
using namespace aitoolkit ::utility ;
Erstellen Sie dann einen Blackboard -Typ:
struct blackboard_type {
int food{ 0 };
int wood{ 0 };
int stone{ 0 };
int gold{ 0 };
};
Erstellen Sie als nächstes eine Klasse für jede Aktion, die Sie ausführen möchten:
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 ;
}
};
Erstellen Sie schließlich einen Evaluator und führen Sie ihn aus:
auto evaluator = evaluator<blackboard_type>(
action_list<blackboard_type>(
collect_food{},
collect_wood{},
collect_stone{},
collect_gold{}
)
);
auto blackboard = blackboard_type{};
evaluator.run(blackboard);
Geben Sie zunächst die Header -Datei an:
# include < aitoolkit/goap.hpp >
using namespace aitoolkit ::goap ;
Erstellen Sie dann eine Blackboard -Klasse, die den Zustand des Planers hält:
struct blackboard_type {
bool has_axe{ false };
int wood{ 0 };
};
NB: Die Tafel muss vergleichbar sein (
a == b
) und Hashable.
Erstellen Sie als nächstes eine Klasse für jede Aktion, die Sie ausführen möchten:
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 ;
}
};
Erstellen Sie schließlich einen Plan und führen Sie ihn aus:
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
}
Weitere Informationen finden Sie in der Dokumentation.
Die Dokumentation ist hier online verfügbar.
Sie können es lokal mit Doxygen erstellen:
$ make docs
Diese Bibliothek wird unter den Bedingungen der MIT -Lizenz veröffentlicht.