From 89c2f13a7fce3174548b7a4f83258294626521e4 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Fri, 25 Aug 2023 22:17:38 +0900 Subject: [PATCH 01/12] add: settlement --- .../PAX_SAPIENTICA/Simulation/Settlement.hpp | 86 +++++++++++++++++++ .../Simulation/SettlementIncludeTest.cpp | 3 + 2 files changed, 89 insertions(+) create mode 100644 Library/PAX_SAPIENTICA/Simulation/Settlement.hpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp new file mode 100644 index 000000000..f3b851be5 --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp @@ -0,0 +1,86 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_SETTLEMENT_HPP +#define PAX_SAPIENTICA_SETTLEMENT_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include + +#include +#include + +namespace paxs { + + /// @brief A class that represents a settlement. + /// @brief 集落を表すクラス + template + class Settlement : public Object { + public: + using Vector2 = paxs::Vector2; + using Object = paxs::Object; + using Agent = paxs::Agent; + + constexpr explicit Settlement(const std::string& id, const std::string& name, const Vector2& pos) noexcept : Object(id, name, pos), agent_count(0) {} + + /// @brief Add an agent to the settlement. + /// @brief 集落にエージェントを追加 + void addAgent(const Agent& agent) { + if (agent_count >= agents.size()) { + throw std::out_of_range("The number of agents has exceeded the limit."); + } + agents[agent_count] = agent; + ++agent_count; + } + + /// @brief Get the number of agents. + /// @brief エージェントの数を取得 + constexpr std::uint_least32_t getAgentCount() const noexcept { return agent_count; } + + /// @brief Get the agent. + /// @brief エージェントを取得 + /// @param id The agent's id. エージェントのID + constexpr Agent getAgent(const std::string& id) const { + for (std::uint_least32_t i = 0; i < agent_count; ++i) { + if (agents[i].getId() == id) { + return agents[i]; + } + } + throw std::out_of_range("The agent does not exist."); + } + + /// @brief Get the agent. + /// @brief エージェントを取得 + constexpr Agent getAgent(const std::string& name, const std::uint_least32_t index) const { + std::uint_least32_t count = 0; + for (std::uint_least32_t i = 0; i < agent_count; ++i) { + if (agents[i].getName() == name) { + if (count == index) { + return agents[i]; + } + ++count; + } + } + throw std::out_of_range("The agent does not exist."); + } + private: + /// @brief エージェントの配列 + std::array agents; + /// @brief エージェントの数 + std::uint_least32_t agent_count; + }; + +} + +#endif // !PAX_SAPIENTICA_SETTLEMENT_HPP \ No newline at end of file diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp new file mode 100644 index 000000000..6793ee14d --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From 60ad6c755eda4f8ce5a13a7e19430c4ed183299d Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Sat, 26 Aug 2023 21:52:38 +0900 Subject: [PATCH 02/12] upd: BaseGroup --- .../PAX_SAPIENTICA/Simulation/BaseGroup.hpp | 58 +++++++++++++ .../PAX_SAPIENTICA/Simulation/Settlement.hpp | 86 ------------------- .../Simulation/BaseGroupIncludeTest.cpp | 3 + .../Simulation/SettlementIncludeTest.cpp | 3 - 4 files changed, 61 insertions(+), 89 deletions(-) create mode 100644 Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp delete mode 100644 Library/PAX_SAPIENTICA/Simulation/Settlement.hpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BaseGroupIncludeTest.cpp delete mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp new file mode 100644 index 000000000..f9fb1a8d6 --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp @@ -0,0 +1,58 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_BASE_GROUP_HPP +#define PAX_SAPIENTICA_BASE_GROUP_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include + +#include +#include + +namespace paxs { + + template + class BaseGroup : public Object { + public: + using Vector2 = paxs::Vector2; + using Object = paxs::Object; + using Agent = paxs::Agent; + + constexpr explicit BaseGroup(const std::string& id, const std::string& name, const Vector2& pos) noexcept : Object(id, name, pos) {} + + /// @brief Add an agent to the settlement. + /// @brief 集落にエージェントを追加 + void addAgent(const Agent& agent) { agents.push_back(agent); } + + /// @brief Get the agent. + /// @brief エージェントを取得 + /// @param id The agent's id. エージェントのID + constexpr Agent getAgent(const std::string& id) const { + for (const auto& agent : agents) { + if (agent.getID() == id) { + return agent; + } + } + throw std::runtime_error("Agent not found."); + } + + private: + /// @brief エージェントの配列 + std::vector agents; + }; + +} + +#endif // !PAX_SAPIENTICA_BASE_GROUP_HPP \ No newline at end of file diff --git a/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp deleted file mode 100644 index f3b851be5..000000000 --- a/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp +++ /dev/null @@ -1,86 +0,0 @@ -/*########################################################################################## - - PAX SAPIENTICA Library 💀🌿🌏 - - [Planning] 2023 As Project - [Production] 2023 As Project - [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA - [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ - -##########################################################################################*/ - -#ifndef PAX_SAPIENTICA_SETTLEMENT_HPP -#define PAX_SAPIENTICA_SETTLEMENT_HPP - -/*########################################################################################## - -##########################################################################################*/ - -#include - -#include -#include - -namespace paxs { - - /// @brief A class that represents a settlement. - /// @brief 集落を表すクラス - template - class Settlement : public Object { - public: - using Vector2 = paxs::Vector2; - using Object = paxs::Object; - using Agent = paxs::Agent; - - constexpr explicit Settlement(const std::string& id, const std::string& name, const Vector2& pos) noexcept : Object(id, name, pos), agent_count(0) {} - - /// @brief Add an agent to the settlement. - /// @brief 集落にエージェントを追加 - void addAgent(const Agent& agent) { - if (agent_count >= agents.size()) { - throw std::out_of_range("The number of agents has exceeded the limit."); - } - agents[agent_count] = agent; - ++agent_count; - } - - /// @brief Get the number of agents. - /// @brief エージェントの数を取得 - constexpr std::uint_least32_t getAgentCount() const noexcept { return agent_count; } - - /// @brief Get the agent. - /// @brief エージェントを取得 - /// @param id The agent's id. エージェントのID - constexpr Agent getAgent(const std::string& id) const { - for (std::uint_least32_t i = 0; i < agent_count; ++i) { - if (agents[i].getId() == id) { - return agents[i]; - } - } - throw std::out_of_range("The agent does not exist."); - } - - /// @brief Get the agent. - /// @brief エージェントを取得 - constexpr Agent getAgent(const std::string& name, const std::uint_least32_t index) const { - std::uint_least32_t count = 0; - for (std::uint_least32_t i = 0; i < agent_count; ++i) { - if (agents[i].getName() == name) { - if (count == index) { - return agents[i]; - } - ++count; - } - } - throw std::out_of_range("The agent does not exist."); - } - private: - /// @brief エージェントの配列 - std::array agents; - /// @brief エージェントの数 - std::uint_least32_t agent_count; - }; - -} - -#endif // !PAX_SAPIENTICA_SETTLEMENT_HPP \ No newline at end of file diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BaseGroupIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BaseGroupIncludeTest.cpp new file mode 100644 index 000000000..f9f144ca9 --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BaseGroupIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp deleted file mode 100644 index 6793ee14d..000000000 --- a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main(){} From b70ebe4dcd102369a568dcc714acfd5b86c92044 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Sun, 27 Aug 2023 02:42:13 +0900 Subject: [PATCH 03/12] add: UnitGroup --- .../PAX_SAPIENTICA/Simulation/BaseGroup.hpp | 6 ++- .../PAX_SAPIENTICA/Simulation/UnitGroup.hpp | 38 +++++++++++++++++++ .../Simulation/UnitGroupIncludeTest.cpp | 3 ++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/UnitGroupIncludeTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp index f9fb1a8d6..1ad34a145 100644 --- a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp @@ -24,13 +24,13 @@ namespace paxs { template - class BaseGroup : public Object { + class BaseGroup { public: using Vector2 = paxs::Vector2; using Object = paxs::Object; using Agent = paxs::Agent; - constexpr explicit BaseGroup(const std::string& id, const std::string& name, const Vector2& pos) noexcept : Object(id, name, pos) {} + constexpr explicit BaseGroup(const std::uint_least32_t id) noexcept : id(id) {} /// @brief Add an agent to the settlement. /// @brief 集落にエージェントを追加 @@ -51,6 +51,8 @@ namespace paxs { private: /// @brief エージェントの配列 std::vector agents; + /// @brief 集落id + std::uint_least32_t id; }; } diff --git a/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp new file mode 100644 index 000000000..1515eb3bd --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp @@ -0,0 +1,38 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#include + +#ifndef PAX_SAPIENTICA_UNIT_HPP +#define PAX_SAPIENTICA_UNIT_HPP + +/*########################################################################################## + +##########################################################################################*/ + +namespace paxs { + + /// @brief A class that represents a unit group. + /// @brief 単位集団を表すクラス + template + class UnitGroup : public BaseGroup + { + public: + using Vector2 = paxs::Vector2; + constexpr explicit UnitGroup(const std::string& id, const Vector2& position) noexcept : BaseGroup(id), position(position) {} + private: + /// @brief 単位集団の位置 + Vector2 position; + }; + +} + +#endif // !PAX_SAPIENTICA_UNIT_HPP \ No newline at end of file diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/UnitGroupIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/UnitGroupIncludeTest.cpp new file mode 100644 index 000000000..c7d35ee06 --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/UnitGroupIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From 61ffa03c7f22e0e08d5bd16b9ce4dbe210833fef Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Mon, 28 Aug 2023 22:04:31 +0900 Subject: [PATCH 04/12] add: BaseGroup --- .../PAX_SAPIENTICA/Simulation/BaseGroup.hpp | 6 ++- .../PAX_SAPIENTICA/Simulation/BasicGroup.hpp | 49 +++++++++++++++++++ .../Simulation/SimulationConst.hpp | 6 +++ .../PAX_SAPIENTICA/Simulation/UnitGroup.hpp | 14 +++++- .../Simulation/BasicGroupIncludeTest.cpp | 3 ++ 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BasicGroupIncludeTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp index 1ad34a145..70e697cc8 100644 --- a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp @@ -34,7 +34,7 @@ namespace paxs { /// @brief Add an agent to the settlement. /// @brief 集落にエージェントを追加 - void addAgent(const Agent& agent) { agents.push_back(agent); } + virtual void addAgent(const Agent& agent) { agents.push_back(agent); } /// @brief Get the agent. /// @brief エージェントを取得 @@ -48,9 +48,11 @@ namespace paxs { throw std::runtime_error("Agent not found."); } - private: + protected: /// @brief エージェントの配列 std::vector agents; + + private: /// @brief 集落id std::uint_least32_t id; }; diff --git a/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp new file mode 100644 index 000000000..e2713e380 --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp @@ -0,0 +1,49 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_BASIC_GROUP_HPP +#define PAX_SAPIENTICA_BASIC_GROUP_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include + +#include + +namespace paxs { + + /// @brief A class that represents a basic group. + /// @brief 基礎集団を表すクラス + template + class BasicGroup : public BaseGroup + { + public: + using Agent = paxs::Agent; + using Vector2 = paxs::Vector2; + constexpr explicit BasicGroup(const std::string& id, const std::vector& positions) noexcept : BaseGroup(id), positions(positions) {} + void addAgent(const Agent& agent) override { + if (this->agents.size() + 1 < basic_group_max) { + this->agents.push_back(agent); + } else { + throw std::runtime_error("The number of agents in the basic group has reached the limit."); + } + } + private: + /// @brief 基礎集団の位置 + std::vector positions; + + }; + +} + +#endif // !PAX_SAPIENTICA_BASIC_GROUP_HPP \ No newline at end of file diff --git a/Library/PAX_SAPIENTICA/Simulation/SimulationConst.hpp b/Library/PAX_SAPIENTICA/Simulation/SimulationConst.hpp index 023018bce..f40bbcdec 100644 --- a/Library/PAX_SAPIENTICA/Simulation/SimulationConst.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/SimulationConst.hpp @@ -18,6 +18,12 @@ namespace paxs { constexpr int pixel_size = 256; // 1画像あたりの縦横のピクセル数 + + constexpr int unit_group_min = 11; // 単位集団の最小人数 + constexpr int unit_group_max = 40; // 単位集団の最大人数 + constexpr int basic_group_min = 41; // 基礎集団の最小人数 + constexpr int basic_group_max = 240; // 基礎集団の最大人数 + constexpr int composite_settlement_min = 82; // 複合集落の最小人数 } #endif // !PAX_SAPIENTICA_SIMULATION_SIMULATION_CONST_HPP \ No newline at end of file diff --git a/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp index 1515eb3bd..8c2a32b7c 100644 --- a/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp @@ -9,8 +9,6 @@ ##########################################################################################*/ -#include - #ifndef PAX_SAPIENTICA_UNIT_HPP #define PAX_SAPIENTICA_UNIT_HPP @@ -18,6 +16,9 @@ ##########################################################################################*/ +#include +#include + namespace paxs { /// @brief A class that represents a unit group. @@ -26,8 +27,17 @@ namespace paxs { class UnitGroup : public BaseGroup { public: + using Agent = paxs::Agent; using Vector2 = paxs::Vector2; constexpr explicit UnitGroup(const std::string& id, const Vector2& position) noexcept : BaseGroup(id), position(position) {} + void addAgent(const Agent& agent) override { + if (this->agents.size() + 1 < unit_group_max) { + this->agents.push_back(agent); + } else { + throw std::runtime_error("The number of agents in the unit group has reached the limit."); + } + } + private: /// @brief 単位集団の位置 Vector2 position; diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BasicGroupIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BasicGroupIncludeTest.cpp new file mode 100644 index 000000000..2c068d542 --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/BasicGroupIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From 8f88f92ca14f016074143115f8f1f13bc69f1fba Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 31 Aug 2023 02:21:38 +0900 Subject: [PATCH 05/12] add: CompositeSettlement --- .../Simulation/CompositeSettlement.hpp | 42 +++++++++++++++++++ .../CompositeSettlementIncludeTest.cpp | 3 ++ 2 files changed, 45 insertions(+) create mode 100644 Library/PAX_SAPIENTICA/Simulation/CompositeSettlement.hpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/CompositeSettlementIncludeTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/CompositeSettlement.hpp b/Library/PAX_SAPIENTICA/Simulation/CompositeSettlement.hpp new file mode 100644 index 000000000..7ea0068b2 --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/CompositeSettlement.hpp @@ -0,0 +1,42 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_COMPOSITE_SETTLEMENT_HPP +#define PAX_SAPIENTICA_COMPOSITE_SETTLEMENT_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include + +namespace paxs { + + /// @brief A class that represents a composite settlement. + /// @brief 複合集落を表すクラス + template + class CompositeSettlement : public BaseGroup { + public: + using Vector2 = paxs::Vector2; + using Object = paxs::Object; + using Agent = paxs::Agent; + + constexpr explicit CompositeSettlement(const std::uint_least32_t id) noexcept : BaseGroup(id) {} + + private: + /// @brief 基礎集団の位置 + std::vector positions; + + }; + +} + +#endif // !PAX_SAPIENTICA_COMPOSITE_SETTLEMENT_HPP \ No newline at end of file diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/CompositeSettlementIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/CompositeSettlementIncludeTest.cpp new file mode 100644 index 000000000..67f5b9de6 --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/CompositeSettlementIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From 066e641874bd452acf64b7ff49a8e662f7d33337 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Sun, 3 Sep 2023 22:31:16 +0900 Subject: [PATCH 06/12] add: Group Test --- .../PAX_SAPIENTICA/Simulation/BaseGroup.hpp | 4 ++++ .../PAX_SAPIENTICA/Simulation/UnitGroup.hpp | 2 +- .../source/Simulation/GroupUnitTest.cpp | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Project/UnitTest/source/Simulation/GroupUnitTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp index 70e697cc8..9cd998eaf 100644 --- a/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp @@ -32,6 +32,10 @@ namespace paxs { constexpr explicit BaseGroup(const std::uint_least32_t id) noexcept : id(id) {} + /// @brief Get the uuid. + /// @brief idを取得 + constexpr std::uint_least32_t getId() const noexcept { return id; } + /// @brief Add an agent to the settlement. /// @brief 集落にエージェントを追加 virtual void addAgent(const Agent& agent) { agents.push_back(agent); } diff --git a/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp index 8c2a32b7c..8381a52db 100644 --- a/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/UnitGroup.hpp @@ -29,7 +29,7 @@ namespace paxs { public: using Agent = paxs::Agent; using Vector2 = paxs::Vector2; - constexpr explicit UnitGroup(const std::string& id, const Vector2& position) noexcept : BaseGroup(id), position(position) {} + constexpr explicit UnitGroup(const std::uint_least32_t& id, const Vector2& position) noexcept : BaseGroup(id), position(position) {} void addAgent(const Agent& agent) override { if (this->agents.size() + 1 < unit_group_max) { this->agents.push_back(agent); diff --git a/Project/UnitTest/source/Simulation/GroupUnitTest.cpp b/Project/UnitTest/source/Simulation/GroupUnitTest.cpp new file mode 100644 index 000000000..1aa72752a --- /dev/null +++ b/Project/UnitTest/source/Simulation/GroupUnitTest.cpp @@ -0,0 +1,19 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#include + +#include + +TEST (UnitGroupUnitTest, constructor) { + paxs::UnitGroup group(0, {0, 0}); + EXPECT_EQ(group.getId(), 0); +} From b4833ce81eea84c9e58bbd61f804c94e520e67a7 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Tue, 5 Sep 2023 22:46:25 +0900 Subject: [PATCH 07/12] add: GroupSimulator --- .../Simulation/GroupSimulator.hpp | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp diff --git a/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp b/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp new file mode 100644 index 000000000..6318af307 --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp @@ -0,0 +1,60 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_GROUP_SIMULATOR_HPP +#define PAX_SAPIENTICA_GROUP_SIMULATOR_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include +#include +#include + +namespace paxs { + + template + class GroupSimulator + { + public: + using Vector2 = paxs::Vector2; + using UnitGroup = paxs::UnitGroup; + using Agent = paxs::Agent; + + constexpr explicit GroupSimulator() = default; + explicit GroupSimulator + explicit Simulator(const std::string& setting_file_path, const Vector2& start_position, const Vector2& end_position, const int z, const unsigned seed = 0) : + environment(std::make_unique(setting_file_path, start_position, end_position, z)), gen(seed) { + if (z <= 0) { + Logger logger("Save/error_log.txt"); + const std::string message = "Z must be greater than 0."; + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); + throw std::runtime_error(message); + } + if (start_position.x < 0 || start_position.y < 0 || end_position.x < 0 || end_position.y < 0) { + Logger logger("Save/error_log.txt"); + const std::string message = "Start position and end position must be greater than or equal to 0."; + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); + throw std::runtime_error(message); + } + } + + private: + std::vector groups; // グループ + std::shared_ptr environment; // 環境 + std::mt19937 gen; // 乱数生成器 + + }; + +} + +#endif // !PAX_SAPIENTICA_GROUP_SIMULATOR_HPP \ No newline at end of file From 33c32b1cb094bcbe297ba5abc24c70f19a662ec8 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Wed, 6 Sep 2023 21:38:16 +0900 Subject: [PATCH 08/12] add: Test --- .../PAX_SAPIENTICA/Simulation/GroupSimulatorIncludeTest.cpp | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/GroupSimulatorIncludeTest.cpp diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/GroupSimulatorIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/GroupSimulatorIncludeTest.cpp new file mode 100644 index 000000000..0769c9cc6 --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/GroupSimulatorIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} From 062b18cdc98c26b7d6ecfc6a2faaa7b67cb3d79e Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Thu, 7 Sep 2023 21:57:04 +0900 Subject: [PATCH 09/12] fix: GroupSimulator --- Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp b/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp index 6318af307..f6544028a 100644 --- a/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp @@ -27,12 +27,11 @@ namespace paxs { { public: using Vector2 = paxs::Vector2; - using UnitGroup = paxs::UnitGroup; + using Environment = paxs::Environment; using Agent = paxs::Agent; constexpr explicit GroupSimulator() = default; - explicit GroupSimulator - explicit Simulator(const std::string& setting_file_path, const Vector2& start_position, const Vector2& end_position, const int z, const unsigned seed = 0) : + explicit GroupSimulator(const std::string& setting_file_path, const Vector2& start_position, const Vector2& end_position, const int z, const unsigned seed = 0) : environment(std::make_unique(setting_file_path, start_position, end_position, z)), gen(seed) { if (z <= 0) { Logger logger("Save/error_log.txt"); @@ -49,7 +48,7 @@ namespace paxs { } private: - std::vector groups; // グループ + std::vector> groups; // グループ std::shared_ptr environment; // 環境 std::mt19937 gen; // 乱数生成器 From d4b26072e8d1486baad93d4d46a1f68448a4fe80 Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:36:49 +0900 Subject: [PATCH 10/12] add: settlement --- Library/PAX_SAPIENTICA/Simulation/Agent.hpp | 2 +- Library/PAX_SAPIENTICA/Simulation/Object.hpp | 6 +- .../PAX_SAPIENTICA/Simulation/Settlement.hpp | 135 ++++++++++++++++++ .../Simulation/SettlementSimulator.hpp | 99 +++++++++++++ .../PAX_SAPIENTICA/Simulation/Simulator.hpp | 7 +- .../Simulation/SettlementIncludeTest.cpp | 3 + .../SettlementSimulatorIncludeTest.cpp | 3 + .../source/Simulation/AgentUnitTest.cpp | 16 +-- 8 files changed, 256 insertions(+), 15 deletions(-) create mode 100644 Library/PAX_SAPIENTICA/Simulation/Settlement.hpp create mode 100644 Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp create mode 100644 Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementSimulatorIncludeTest.cpp diff --git a/Library/PAX_SAPIENTICA/Simulation/Agent.hpp b/Library/PAX_SAPIENTICA/Simulation/Agent.hpp index cba93d058..aae154eef 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Agent.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Agent.hpp @@ -36,7 +36,7 @@ namespace paxs { using Vector2 = paxs::Vector2; using Environment = paxs::Environment; - constexpr explicit Agent(const std::string& id, const std::string& name, const Vector2& pos, const std::uint_least8_t gen, const std::uint_least32_t age, const std::uint_least32_t life_span, const std::shared_ptr env) noexcept + constexpr explicit Agent(const std::uint_least32_t id, const std::string& name, const Vector2& pos, const std::uint_least8_t gen, const std::uint_least32_t age, const std::uint_least32_t life_span, const std::shared_ptr env) noexcept : Object(id, name, pos), gender(gen), age(age), life_span(life_span), environment(env) {} /// @brief Move the agent. diff --git a/Library/PAX_SAPIENTICA/Simulation/Object.hpp b/Library/PAX_SAPIENTICA/Simulation/Object.hpp index cbb907c9d..5910f5c7c 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Object.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Object.hpp @@ -28,10 +28,10 @@ namespace paxs { public: using Vector2 = paxs::Vector2; - constexpr explicit Object(const std::string& id, const std::string& name, const Vector2& position) noexcept : id(id), name(name), position(position) {} + constexpr explicit Object(const std::uint_least32_t id, const std::string& name, const Vector2& position) noexcept : id(id), name(name), position(position) {} /// @brief Get the object's id. オブジェクトのIDを取得 - std::string getId() const noexcept { return id; } + std::uint_least32_t getId() const noexcept { return id; } /// @brief Get the coordinate x. オブジェクトの座標xを取得 constexpr GridType getX() const noexcept { return position.x; } @@ -62,7 +62,7 @@ namespace paxs { } protected: - std::string id; // オブジェクトのID + std::uint_least32_t id; // オブジェクトのID std::string name; // オブジェクトの名前 Vector2 position; // オブジェクトの座標 }; diff --git a/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp new file mode 100644 index 000000000..b5897176e --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp @@ -0,0 +1,135 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_SETTLEMENT_HPP +#define PAX_SAPIENTICA_SETTLEMENT_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include +#include + +#include +#include +#include + +namespace paxs { + + template + class Settlement { + public: + using Vector2 = paxs::Vector2; + using Object = paxs::Object; + using Agent = paxs::Agent; + + constexpr explicit Settlement(const std::uint_least32_t id) noexcept : id(id) {} + + /// @brief Get the uuid. + /// @brief idを取得 + constexpr std::uint_least32_t getId() const noexcept { return id; } + + /// @brief Add an agent to the settlement. + /// @brief 集落にエージェントを追加 + void addAgent(const Agent& agent) noexcept { agents.push_back(agent); } + + /// @brief Set the position of the settlement. + /// @brief 集落の座標を設定 + void setPosition(const Vector2& position) noexcept { positions.push_back(position); } + + /// @brief Get the agent. + /// @brief エージェントを取得 + /// @param id The agent's id. エージェントのID + Agent& getAgent(const std::uint_least32_t id) const { + auto it = std::find_if(agents.begin(), agents.end(), [id](const Agent& agent) { return agent.getId() == id; }); + if (it == agents.end()) { + paxs::Logger logger("Save/error_log.txt"); + const std::string message = "Agent not found."; + logger.log(Logger::Level::WARNING, __FILE__, __LINE__, message); + throw std::runtime_error(message); + } + return *it; + } + + /// @brief Pre update. + /// @brief 事前更新 + void preUpdate(std::mt19937& engine, std::vector& closest_settlements) noexcept { + move(engine); + marriage(); + birth(); + emigration(closest_settlements); + } + + /// @brief On update. + /// @brief 更新 + void onUpdate() noexcept { + ageUpdate(); + death(); + } + + private: + /// @brief 集落id + std::uint_least32_t id; + /// @brief エージェントの配列 + std::vector agents; + /// @brief 集落の座標 + std::vector positions; + + /// @brief Move. + /// @brief 移動 + void move(std::mt19937& engine) noexcept { + // 0.1%の確率で移動 + std::uniform_int_distribution<> dist(0, 1000); + if (dist(engine) != 0) return; + + // 座標を移動 + // TODO: 移動先の座標を決定 + + } + + /// @brief Marriage. + /// @brief 婚姻 + void marriage() noexcept { + // TODO: 結婚 + } + + /// @brief Birth. + /// @brief 出産 + void birth() noexcept { + // TODO: 出産 + } + + /// @brief Emigration. + /// @brief 渡来 + void emigration(std::vector& closest_settlements) noexcept { + // TODO: 渡来 + } + + /// @brief Age update. + /// @brief 年齢更新 + void ageUpdate() noexcept { + for (Agent& agent : agents) { + agent.incrementAge(); + } + } + + /// @brief Death. + /// @brief 死亡 + void death() noexcept { + agents.erase(std::remove_if(agents.begin(), agents.end(), [](const Agent& agent) { return agent.isDead(); }), agents.end()); + } + + }; + +} + +#endif // !PAX_SAPIENTICA_SETTLEMENT_HPP \ No newline at end of file diff --git a/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp b/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp new file mode 100644 index 000000000..07eb62932 --- /dev/null +++ b/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp @@ -0,0 +1,99 @@ +/*########################################################################################## + + PAX SAPIENTICA Library 💀🌿🌏 + + [Planning] 2023 As Project + [Production] 2023 As Project + [Contact Us] wanotaitei@gmail.com https://github.com/AsPJT/PAX_SAPIENTICA + [License] Distributed under the CC0 1.0. https://creativecommons.org/publicdomain/zero/1.0/ + +##########################################################################################*/ + +#ifndef PAX_SAPIENTICA_SETTLEMENT_SIMULATOR_HPP +#define PAX_SAPIENTICA_SETTLEMENT_SIMULATOR_HPP + +/*########################################################################################## + +##########################################################################################*/ + +#include +#include +#include + +#include +#include +#include + +namespace paxs { + + template + class SettlementSimulator { + public: + using Agent = paxs::Agent; + using Environment = paxs::Environment; + using Settlement = paxs::Settlement; + using Vector2 = paxs::Vector2; + + constexpr explicit SettlementSimulator() = default; + + explicit SettlementSimulator(const std::string& setting_file_path, const Vector2& start_position, const Vector2& end_position, const int z, const unsigned seed = 0) : + environment(std::make_unique(setting_file_path, start_position, end_position, z)), gen(seed) { + if (z <= 0) { + Logger logger("Save/error_log.txt"); + const std::string message = "Z must be greater than 0."; + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); + throw std::runtime_error(message); + } + if (start_position.x < 0 || start_position.y < 0 || end_position.x < 0 || end_position.y < 0) { + Logger logger("Save/error_log.txt"); + const std::string message = "Start position and end position must be greater than or equal to 0."; + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); + throw std::runtime_error(message); + } + } + + /// @brief Initialize the simulator. + /// @brief 集落の初期化 + /// @details 集落をクリアし、地域ごとに指定されたエージェント数になるようにランダムに配置する + void init() { + settlements.clear(); + randomizeSettlements(); + } + + /// @brief Run the simulation for the specified number of steps. + /// @brief シミュレーションを指定されたステップ数だけ実行する + void run(const int step_count) noexcept { + for(int i = 0; i < step_count; ++i) { + step(); + } + } + + /// @brief Execute the simulation for the one step. + /// @brief シミュレーションを1ステップ実行する + void step() noexcept { + for (auto& settlement : settlements) { + settlement.preUpdate(); + } + + for (auto& settlement : settlements) { + settlement.onUpdate(); + } + } + + private: + std::vector settlements; + std::shared_ptr environment; + std::mt19937 gen; // 乱数生成器 + std::uniform_int_distribution<> gender_dist{0, 1}; // 性別の乱数分布 + std::uniform_int_distribution<> life_exp_dist{50, 100}; // 寿命の乱数分布 + + /// @brief Randomly place settlements. + /// @brief 集落をランダムに配置する + void randomizeSettlements() noexcept { + // TODO: 未実装 + } + + }; +} + +#endif // !PAX_SAPIENTICA_SETTLEMENT_SIMULATOR_HPP \ No newline at end of file diff --git a/Library/PAX_SAPIENTICA/Simulation/Simulator.hpp b/Library/PAX_SAPIENTICA/Simulation/Simulator.hpp index 54482a017..a71b37d7c 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Simulator.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Simulator.hpp @@ -88,11 +88,11 @@ namespace paxs { agent.move(); } catch (const std::runtime_error&) { Logger logger("Save/error_log.txt"); - logger.log(Logger::Level::ERROR, __FILE__, __LINE__, "Failed to move agent. Agent id: " + agent.getId()); + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, "Failed to move agent. Agent id: " + std::to_string(agent.getId())); } } - agents.erase(std::remove_if(agents.begin(), agents.end(),[](const Agent& agent) { return agent.isDead(); }),agents.end()); + agents.erase(std::remove_if(agents.begin(), agents.end(), [](const Agent& agent) { return agent.isDead(); }), agents.end()); } @@ -135,7 +135,8 @@ namespace paxs { throw std::runtime_error(message); } - agents.push_back(Agent( "", "", position, static_cast(gender_dist(gen)), age_dist(gen), life_exp_dist(gen), environment)); + // TODO: uuidの生成 + agents.push_back(Agent( 0, "", position, static_cast(gender_dist(gen)), age_dist(gen), life_exp_dist(gen), environment)); } StatusDisplayer::displayProgressBar(agent_count, agent_count); std::cout << std::endl; diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp new file mode 100644 index 000000000..6793ee14d --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementSimulatorIncludeTest.cpp b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementSimulatorIncludeTest.cpp new file mode 100644 index 000000000..02695f211 --- /dev/null +++ b/Project/IncludeTest/source/PAX_SAPIENTICA/Simulation/SettlementSimulatorIncludeTest.cpp @@ -0,0 +1,3 @@ +#include + +int main(){} diff --git a/Project/UnitTest/source/Simulation/AgentUnitTest.cpp b/Project/UnitTest/source/Simulation/AgentUnitTest.cpp index 434ebb10c..248840fc0 100644 --- a/Project/UnitTest/source/Simulation/AgentUnitTest.cpp +++ b/Project/UnitTest/source/Simulation/AgentUnitTest.cpp @@ -29,42 +29,42 @@ class EnvironmentMock : public paxs::Environment { TEST (AgentUnitTest, move) { std::shared_ptr> env = std::make_shared>(); - paxs::Agent agent("0", "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent(0, "test", paxs::Vector2(0, 0), 0, 0, 0, env); agent.move(paxs::Vector2(1, 1)); EXPECT_EQ(agent.getPosition(), paxs::Vector2(1, 1)); } TEST (AgentUnitTest, isDead) { std::shared_ptr> env = std::make_shared>(); - paxs::Agent agent("0", "test", paxs::Vector2(0, 0), 0, 10, 5, env); + paxs::Agent agent(0, "test", paxs::Vector2(0, 0), 0, 10, 5, env); EXPECT_TRUE(agent.isDead()); } TEST (AgentUnitTest, getAge) { std::shared_ptr> env = std::make_shared>(); - paxs::Agent agent("0", "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent(0, "test", paxs::Vector2(0, 0), 0, 0, 0, env); EXPECT_EQ(agent.getAge(), 0); } TEST (AgentUnitTest, updateAge) { std::shared_ptr> env = std::make_shared>(); - paxs::Agent agent("0", "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent(0, "test", paxs::Vector2(0, 0), 0, 0, 0, env); agent.incrementAge(); EXPECT_EQ(agent.getAge(), 1); } TEST (AgentUnitTest, getGender) { std::shared_ptr> env = std::make_shared>(); - paxs::Agent agent("0", "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent(0, "test", paxs::Vector2(0, 0), 0, 0, 0, env); EXPECT_EQ(agent.getGender(), 0); } TEST (AgentUnitTest, operatorEqual) { std::shared_ptr> env = std::make_shared>(); - paxs::Agent agent1("0", "test", paxs::Vector2(0, 0), 0, 0, 0, env); - paxs::Agent agent2("0", "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent1(0, "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent2(0, "test", paxs::Vector2(0, 0), 0, 0, 0, env); EXPECT_TRUE(agent1 == agent2); - paxs::Agent agent3("1", "test", paxs::Vector2(0, 0), 0, 0, 0, env); + paxs::Agent agent3(1, "test", paxs::Vector2(0, 0), 0, 0, 0, env); EXPECT_FALSE(agent1 == agent3); } From 156bb41dcd814355637756b66dab88f57d00a62f Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:05:12 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix:=20filter=E3=81=AE=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/reviewdog-cpplint.yml | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/reviewdog-cpplint.yml b/.github/workflows/reviewdog-cpplint.yml index 6e01f6cbc..a246d2467 100644 --- a/.github/workflows/reviewdog-cpplint.yml +++ b/.github/workflows/reviewdog-cpplint.yml @@ -16,19 +16,20 @@ jobs: github_token: ${{ secrets.github_token }} reporter: github-pr-review flags: --linelength=150 - filter: "-build/include_alpha\ - ,-build/include_what_you_use\ - ,-build/storage_class\ - ,-readability/braces\ - ,-readability/casting\ - ,-readability/fn_size\ - ,-whitespace/braces\ - ,-whitespace/comma\ - ,-whitespace/comments\ - ,-whitespace/end_of_line\ - ,-whitespace/ending_newline\ - ,-whitespace/indent\ - ,-whitespace/newline\ - ,-whitespace/operators\ - ,-whitespace/parens\ + filter: "build/include_alpha\ + ,build/include_what_you_use\ + ,build/storage_class\ + ,readability/braces\ + ,readability/casting\ + ,readability/fn_size\ + ,whitespace/braces\ + ,whitespace/comma\ + ,whitespace/comments\ + ,whitespace/end_of_line\ + ,whitespace/ending_newline\ + ,whitespace/indent\ + ,whitespace/newline\ + ,whitespace/operators\ + ,whitespace/parens\ + ,whitespace/line_length\ " From 651a601d3018809813e9dbf4940f5fa67cc6c36c Mon Sep 17 00:00:00 2001 From: guinpen98 <83969826+guinpen98@users.noreply.github.com> Date: Mon, 18 Sep 2023 19:08:43 +0900 Subject: [PATCH 12/12] fix: line length --- Library/PAX_SAPIENTICA/Simulation/Agent.hpp | 5 ++-- .../PAX_SAPIENTICA/Simulation/BasicGroup.hpp | 5 +++- .../Simulation/GroupSimulator.hpp | 29 ++++++++++--------- Library/PAX_SAPIENTICA/Simulation/Object.hpp | 3 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Library/PAX_SAPIENTICA/Simulation/Agent.hpp b/Library/PAX_SAPIENTICA/Simulation/Agent.hpp index aae154eef..0f7618c07 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Agent.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Agent.hpp @@ -36,8 +36,9 @@ namespace paxs { using Vector2 = paxs::Vector2; using Environment = paxs::Environment; - constexpr explicit Agent(const std::uint_least32_t id, const std::string& name, const Vector2& pos, const std::uint_least8_t gen, const std::uint_least32_t age, const std::uint_least32_t life_span, const std::shared_ptr env) noexcept - : Object(id, name, pos), gender(gen), age(age), life_span(life_span), environment(env) {} + constexpr explicit Agent(const std::uint_least32_t id, const std::string& name, const Vector2& pos, const std::uint_least8_t gen, + const std::uint_least32_t age, const std::uint_least32_t life_span, const std::shared_ptr env) noexcept + : Object(id, name, pos), gender(gen), age(age), life_span(life_span), environment(env) {} /// @brief Move the agent. /// @brief エージェントを移動させる diff --git a/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp b/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp index e2713e380..5d04c4094 100644 --- a/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp @@ -30,7 +30,10 @@ namespace paxs { public: using Agent = paxs::Agent; using Vector2 = paxs::Vector2; - constexpr explicit BasicGroup(const std::string& id, const std::vector& positions) noexcept : BaseGroup(id), positions(positions) {} + + constexpr explicit BasicGroup(const std::string& id, const std::vector& positions) noexcept + : BaseGroup(id), positions(positions) {} + void addAgent(const Agent& agent) override { if (this->agents.size() + 1 < basic_group_max) { this->agents.push_back(agent); diff --git a/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp b/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp index f6544028a..9d00f011c 100644 --- a/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp @@ -31,21 +31,22 @@ namespace paxs { using Agent = paxs::Agent; constexpr explicit GroupSimulator() = default; - explicit GroupSimulator(const std::string& setting_file_path, const Vector2& start_position, const Vector2& end_position, const int z, const unsigned seed = 0) : - environment(std::make_unique(setting_file_path, start_position, end_position, z)), gen(seed) { - if (z <= 0) { - Logger logger("Save/error_log.txt"); - const std::string message = "Z must be greater than 0."; - logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); - throw std::runtime_error(message); - } - if (start_position.x < 0 || start_position.y < 0 || end_position.x < 0 || end_position.y < 0) { - Logger logger("Save/error_log.txt"); - const std::string message = "Start position and end position must be greater than or equal to 0."; - logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); - throw std::runtime_error(message); - } + explicit GroupSimulator(const std::string& setting_file_path, + const Vector2& start_position, const Vector2& end_position, const int z, const unsigned seed = 0) + : environment(std::make_unique(setting_file_path, start_position, end_position, z)), gen(seed) { + if (z <= 0) { + Logger logger("Save/error_log.txt"); + const std::string message = "Z must be greater than 0."; + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); + throw std::runtime_error(message); } + if (start_position.x < 0 || start_position.y < 0 || end_position.x < 0 || end_position.y < 0) { + Logger logger("Save/error_log.txt"); + const std::string message = "Start position and end position must be greater than or equal to 0."; + logger.log(Logger::Level::ERROR, __FILE__, __LINE__, message); + throw std::runtime_error(message); + } + } private: std::vector> groups; // グループ diff --git a/Library/PAX_SAPIENTICA/Simulation/Object.hpp b/Library/PAX_SAPIENTICA/Simulation/Object.hpp index 5910f5c7c..d4434bc89 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Object.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Object.hpp @@ -28,7 +28,8 @@ namespace paxs { public: using Vector2 = paxs::Vector2; - constexpr explicit Object(const std::uint_least32_t id, const std::string& name, const Vector2& position) noexcept : id(id), name(name), position(position) {} + constexpr explicit Object(const std::uint_least32_t id, const std::string& name, const Vector2& position) noexcept + : id(id), name(name), position(position) {} /// @brief Get the object's id. オブジェクトのIDを取得 std::uint_least32_t getId() const noexcept { return id; }