From c06ede0f600ce185da348a8540a67576fff54002 Mon Sep 17 00:00:00 2001 From: Felipe Nunes Date: Thu, 31 Oct 2024 12:27:28 -0300 Subject: [PATCH] [decision-ms] Add decision world (#76) Adds decision world with allies, enemies, ball and game status (referee) information. --------- Co-authored-by: ersaraujo --- .../processing/entities/CMakeLists.txt | 5 +++ .../decision/processing/entities/world.cpp | 33 +++++++++++++++++ .../decision/processing/entities/world.h | 37 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 decision-ms/decision-guardiola/decision/processing/entities/CMakeLists.txt create mode 100644 decision-ms/decision-guardiola/decision/processing/entities/world.cpp create mode 100644 decision-ms/decision-guardiola/decision/processing/entities/world.h diff --git a/decision-ms/decision-guardiola/decision/processing/entities/CMakeLists.txt b/decision-ms/decision-guardiola/decision/processing/entities/CMakeLists.txt new file mode 100644 index 00000000..f6622e4e --- /dev/null +++ b/decision-ms/decision-guardiola/decision/processing/entities/CMakeLists.txt @@ -0,0 +1,5 @@ +robocin_cpp_library( + NAME entities + HDRS world.h + SRCS world.cpp +) diff --git a/decision-ms/decision-guardiola/decision/processing/entities/world.cpp b/decision-ms/decision-guardiola/decision/processing/entities/world.cpp new file mode 100644 index 00000000..30206cce --- /dev/null +++ b/decision-ms/decision-guardiola/decision/processing/entities/world.cpp @@ -0,0 +1,33 @@ +#include "decision/processing/entities/world.h" + +#include "decision/processing/messages/referee/game_status_message.h" + +namespace decision { + +void World::update(std::optional>& allies, + std::optional>& enemies, + std::optional& ball, + std::optional& field, + std::optional& game_status) { + if (allies.has_value()) { + this->allies = allies.value(); + } + + if (enemies.has_value()) { + this->enemies = enemies.value(); + } + + if (ball.has_value()) { + this->ball = std::move(ball.value()); + } + + if (field.has_value()) { + this->field = std::move(field.value()); + } + + if (game_status.has_value()) { + this->game_status = std::move(game_status.value()); + } +} + +} // namespace decision diff --git a/decision-ms/decision-guardiola/decision/processing/entities/world.h b/decision-ms/decision-guardiola/decision/processing/entities/world.h new file mode 100644 index 00000000..c8c421b2 --- /dev/null +++ b/decision-ms/decision-guardiola/decision/processing/entities/world.h @@ -0,0 +1,37 @@ +#ifndef DECISION_PROCESSING_ENTITIES_WORLD_H +#define DECISION_PROCESSING_ENTITIES_WORLD_H + +#include "decision/processing/messages/perception/ball/ball_message.h" +#include "decision/processing/messages/perception/field/field_message.h" +#include "decision/processing/messages/perception/robot/robot_message.h" +#include "decision/processing/messages/referee/game_status_message.h" + +namespace decision { + +class World { + public: + World() = default; + + World(const World&) = delete; + World& operator=(const World&) = delete; + World(World&&) noexcept = default; + World& operator=(World&&) noexcept = default; + + virtual ~World() = default; + + std::span allies; + std::span enemies; + BallMessage ball; + FieldMessage field; + GameStatusMessage game_status; // referee + + void update(std::optional>& allies, + std::optional>& enemies, + std::optional& ball, + std::optional& field, + std::optional& game_status); +}; + +} // namespace decision + +#endif // DECISION_PROCESSING_ENTITIES_WORLD_H