action_list
This commit is contained in:
parent
89925e286e
commit
30407477ea
2 changed files with 94 additions and 25 deletions
5
s2ga.hpp
5
s2ga.hpp
|
@ -4,6 +4,7 @@
|
|||
#include <type_traits>
|
||||
#include <iostream>
|
||||
#include <format>
|
||||
#include <vector>
|
||||
|
||||
namespace s2ga
|
||||
{
|
||||
|
@ -145,6 +146,10 @@ namespace s2ga
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename E>
|
||||
requires std::is_enum_v<E>
|
||||
using action_list = std::vector<action<E>>;
|
||||
}; // namespace s2ga
|
||||
|
||||
inline void foo()
|
||||
|
|
114
tests/test.cpp
114
tests/test.cpp
|
@ -13,35 +13,99 @@ using namespace s2ga;
|
|||
|
||||
TEST_CASE("(dummy)", "[test]")
|
||||
{
|
||||
enum State
|
||||
enum State
|
||||
{
|
||||
HAS_AMMO,
|
||||
HAS_WEAPON,
|
||||
ENEMY_ALIVE,
|
||||
SATISFIED
|
||||
HUNGRY,
|
||||
HAS_FOOD,
|
||||
HAS_HOUSE,
|
||||
HAS_CLOTHES,
|
||||
HAS_WOOD,
|
||||
HAS_TOOLS,
|
||||
HAS_FABRIC,
|
||||
HAS_ANIMAL_SKIN,
|
||||
IS_WET,
|
||||
HAS_FIRE,
|
||||
IS_RAINING
|
||||
};
|
||||
|
||||
action<State> shoot_action;
|
||||
shoot_action.name = "SHOOT";
|
||||
shoot_action.positive_preconds = bm<State>(HAS_AMMO, HAS_WEAPON, ENEMY_ALIVE);
|
||||
shoot_action.negative_preconds = bm<State>(SATISFIED);
|
||||
shoot_action.positive_effects = bm<State>(SATISFIED);
|
||||
shoot_action.negative_effects = bm<State>(ENEMY_ALIVE);
|
||||
shoot_action.cost = 0.5f;
|
||||
action_list<State> actions =
|
||||
{
|
||||
{
|
||||
.name = "COLLECT FRUITS",
|
||||
.cost = 2.0f,
|
||||
.positive_effects = bm<State>(HAS_FOOD),
|
||||
.negative_preconds = bm<State>(IS_RAINING),
|
||||
},
|
||||
{
|
||||
.name = "COLLECT FRUITS",
|
||||
.cost = 2.0f,
|
||||
.positive_effects = bm<State>(HAS_FOOD),
|
||||
.negative_preconds = bm<State>(IS_RAINING),
|
||||
},
|
||||
{
|
||||
.name = "MAKE FISH TRAP",
|
||||
.cost = 0.5f,
|
||||
.positive_effects = bm<State>(HAS_FOOD),
|
||||
.negative_effects = bm<State>(HAS_WOOD),
|
||||
.positive_preconds = bm<State>(HAS_TOOLS),
|
||||
.negative_preconds = bm<State>(IS_WET),
|
||||
},
|
||||
{
|
||||
.name = "BUILD HOUSE",
|
||||
.cost = 8.0f,
|
||||
.positive_effects = bm<State>(HAS_HOUSE),
|
||||
.negative_effects = bm<State>(HAS_WOOD, IS_WET),
|
||||
.positive_preconds = bm<State>(HAS_TOOLS, HAS_WOOD),
|
||||
.negative_preconds = bm<State>(HAS_HOUSE),
|
||||
},
|
||||
{
|
||||
.name = "CRAFT TOOLS",
|
||||
.cost = 5.0f,
|
||||
.positive_effects = bm<State>(HAS_TOOLS),
|
||||
.negative_effects = bm<State>(HAS_WOOD),
|
||||
.positive_preconds = bm<State>(HAS_WOOD),
|
||||
},
|
||||
{
|
||||
.name = "MAKE CLOTHES",
|
||||
.cost = 4.0f,
|
||||
.positive_effects = bm<State>(HAS_CLOTHES),
|
||||
.negative_effects = bm<State>(HAS_FABRIC),
|
||||
.positive_preconds = bm<State>(HAS_FABRIC),
|
||||
.negative_preconds = bm<State>(IS_WET),
|
||||
},
|
||||
{
|
||||
.name = "HUNT ANIMAL",
|
||||
.cost = 6.0f,
|
||||
.positive_effects = bm<State>(HAS_ANIMAL_SKIN, HAS_FOOD),
|
||||
.negative_effects = bm<State>(HUNGRY),
|
||||
.positive_preconds = bm<State>(HAS_TOOLS),
|
||||
.negative_preconds = bm<State>(IS_RAINING),
|
||||
},
|
||||
{
|
||||
.name = "MAKE FIRE",
|
||||
.cost = 2.0f,
|
||||
.positive_effects = bm<State>(HAS_FIRE),
|
||||
.negative_effects = bm<State>(HAS_WOOD, IS_WET),
|
||||
.positive_preconds = bm<State>(HAS_WOOD),
|
||||
},
|
||||
{
|
||||
.name = "COLLECT WOOD",
|
||||
.cost = 2.0f,
|
||||
.positive_effects = bm<State>(HAS_WOOD),
|
||||
.negative_preconds = bm<State>(IS_RAINING),
|
||||
},
|
||||
{
|
||||
.name = "WAIT OUT RAIN",
|
||||
.cost = 5.0f,
|
||||
.negative_effects = bm<State>(IS_RAINING),
|
||||
.positive_preconds = bm<State>(IS_RAINING),
|
||||
}
|
||||
};
|
||||
|
||||
shoot_action.print();
|
||||
/*
|
||||
Will print this:
|
||||
[SHOOT, 0.5]
|
||||
Effects:
|
||||
-ENEMY_ALIVE
|
||||
+SATISFIED
|
||||
Preconditions:
|
||||
+HAS_AMMO
|
||||
+HAS_WEAPON
|
||||
+ENEMY_ALIVE
|
||||
-SATISFIED
|
||||
*/
|
||||
for(auto& action: actions)
|
||||
{
|
||||
action.print();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("lehmer64 rng", "[test]")
|
||||
|
|
Loading…
Reference in a new issue