From 30407477ea4b6183d05bb21339f121d7fbce3456 Mon Sep 17 00:00:00 2001 From: NukeBird Date: Wed, 12 Mar 2025 21:44:21 +0300 Subject: [PATCH] action_list --- s2ga.hpp | 5 +++ tests/test.cpp | 114 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 94 insertions(+), 25 deletions(-) diff --git a/s2ga.hpp b/s2ga.hpp index 9669893..6523cd5 100644 --- a/s2ga.hpp +++ b/s2ga.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace s2ga { @@ -145,6 +146,10 @@ namespace s2ga } } }; + + template + requires std::is_enum_v + using action_list = std::vector>; }; // namespace s2ga inline void foo() diff --git a/tests/test.cpp b/tests/test.cpp index d00ac10..d84c1a3 100644 --- a/tests/test.cpp +++ b/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 shoot_action; - shoot_action.name = "SHOOT"; - shoot_action.positive_preconds = bm(HAS_AMMO, HAS_WEAPON, ENEMY_ALIVE); - shoot_action.negative_preconds = bm(SATISFIED); - shoot_action.positive_effects = bm(SATISFIED); - shoot_action.negative_effects = bm(ENEMY_ALIVE); - shoot_action.cost = 0.5f; + action_list actions = + { + { + .name = "COLLECT FRUITS", + .cost = 2.0f, + .positive_effects = bm(HAS_FOOD), + .negative_preconds = bm(IS_RAINING), + }, + { + .name = "COLLECT FRUITS", + .cost = 2.0f, + .positive_effects = bm(HAS_FOOD), + .negative_preconds = bm(IS_RAINING), + }, + { + .name = "MAKE FISH TRAP", + .cost = 0.5f, + .positive_effects = bm(HAS_FOOD), + .negative_effects = bm(HAS_WOOD), + .positive_preconds = bm(HAS_TOOLS), + .negative_preconds = bm(IS_WET), + }, + { + .name = "BUILD HOUSE", + .cost = 8.0f, + .positive_effects = bm(HAS_HOUSE), + .negative_effects = bm(HAS_WOOD, IS_WET), + .positive_preconds = bm(HAS_TOOLS, HAS_WOOD), + .negative_preconds = bm(HAS_HOUSE), + }, + { + .name = "CRAFT TOOLS", + .cost = 5.0f, + .positive_effects = bm(HAS_TOOLS), + .negative_effects = bm(HAS_WOOD), + .positive_preconds = bm(HAS_WOOD), + }, + { + .name = "MAKE CLOTHES", + .cost = 4.0f, + .positive_effects = bm(HAS_CLOTHES), + .negative_effects = bm(HAS_FABRIC), + .positive_preconds = bm(HAS_FABRIC), + .negative_preconds = bm(IS_WET), + }, + { + .name = "HUNT ANIMAL", + .cost = 6.0f, + .positive_effects = bm(HAS_ANIMAL_SKIN, HAS_FOOD), + .negative_effects = bm(HUNGRY), + .positive_preconds = bm(HAS_TOOLS), + .negative_preconds = bm(IS_RAINING), + }, + { + .name = "MAKE FIRE", + .cost = 2.0f, + .positive_effects = bm(HAS_FIRE), + .negative_effects = bm(HAS_WOOD, IS_WET), + .positive_preconds = bm(HAS_WOOD), + }, + { + .name = "COLLECT WOOD", + .cost = 2.0f, + .positive_effects = bm(HAS_WOOD), + .negative_preconds = bm(IS_RAINING), + }, + { + .name = "WAIT OUT RAIN", + .cost = 5.0f, + .negative_effects = bm(IS_RAINING), + .positive_preconds = bm(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]")