-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from AsPJT/feature/guinpen98/add-settlement
集落を追加
- Loading branch information
Showing
21 changed files
with
583 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*########################################################################################## | ||
PAX SAPIENTICA Library 💀🌿🌏 | ||
[Planning] 2023 As Project | ||
[Production] 2023 As Project | ||
[Contact Us] [email protected] 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 <vector> | ||
|
||
#include <PAX_SAPIENTICA/Simulation/Agent.hpp> | ||
#include <PAX_SAPIENTICA/Simulation/Object.hpp> | ||
|
||
namespace paxs { | ||
|
||
template <typename GridType> | ||
class BaseGroup { | ||
public: | ||
using Vector2 = paxs::Vector2<GridType>; | ||
using Object = paxs::Object<GridType>; | ||
using Agent = paxs::Agent<GridType>; | ||
|
||
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); } | ||
|
||
/// @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."); | ||
} | ||
|
||
protected: | ||
/// @brief エージェントの配列 | ||
std::vector<Agent> agents; | ||
|
||
private: | ||
/// @brief 集落id | ||
std::uint_least32_t id; | ||
}; | ||
|
||
} | ||
|
||
#endif // !PAX_SAPIENTICA_BASE_GROUP_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*########################################################################################## | ||
PAX SAPIENTICA Library 💀🌿🌏 | ||
[Planning] 2023 As Project | ||
[Production] 2023 As Project | ||
[Contact Us] [email protected] 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 <vector> | ||
|
||
#include <PAX_SAPIENTICA/Simulation/BaseGroup.hpp> | ||
|
||
namespace paxs { | ||
|
||
/// @brief A class that represents a basic group. | ||
/// @brief 基礎集団を表すクラス | ||
template <typename GridType> | ||
class BasicGroup : public BaseGroup<GridType> | ||
{ | ||
public: | ||
using Agent = paxs::Agent<GridType>; | ||
using Vector2 = paxs::Vector2<GridType>; | ||
|
||
constexpr explicit BasicGroup(const std::string& id, const std::vector<Vector2>& positions) noexcept | ||
: BaseGroup<GridType>(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<Vector2> positions; | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif // !PAX_SAPIENTICA_BASIC_GROUP_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*########################################################################################## | ||
PAX SAPIENTICA Library 💀🌿🌏 | ||
[Planning] 2023 As Project | ||
[Production] 2023 As Project | ||
[Contact Us] [email protected] 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 <PAX_SAPIENTICA/Simulation/BaseGroup.hpp> | ||
|
||
namespace paxs { | ||
|
||
/// @brief A class that represents a composite settlement. | ||
/// @brief 複合集落を表すクラス | ||
template <typename GridType> | ||
class CompositeSettlement : public BaseGroup<GridType> { | ||
public: | ||
using Vector2 = paxs::Vector2<GridType>; | ||
using Object = paxs::Object<GridType>; | ||
using Agent = paxs::Agent<GridType>; | ||
|
||
constexpr explicit CompositeSettlement(const std::uint_least32_t id) noexcept : BaseGroup<GridType>(id) {} | ||
|
||
private: | ||
/// @brief 基礎集団の位置 | ||
std::vector<Vector2> positions; | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif // !PAX_SAPIENTICA_COMPOSITE_SETTLEMENT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*########################################################################################## | ||
PAX SAPIENTICA Library 💀🌿🌏 | ||
[Planning] 2023 As Project | ||
[Production] 2023 As Project | ||
[Contact Us] [email protected] 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 <PAX_SAPIENTICA/Simulation/BasicGroup.hpp> | ||
#include <PAX_SAPIENTICA/Simulation/CompositeSettlement.hpp> | ||
#include <PAX_SAPIENTICA/Simulation/UnitGroup.hpp> | ||
|
||
namespace paxs { | ||
|
||
template <typename GridType> | ||
class GroupSimulator | ||
{ | ||
public: | ||
using Vector2 = paxs::Vector2<GridType>; | ||
using Environment = paxs::Environment<GridType>; | ||
using Agent = paxs::Agent<GridType>; | ||
|
||
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<Environment>(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<BaseGroup<GridType>> groups; // グループ | ||
std::shared_ptr<Environment> environment; // 環境 | ||
std::mt19937 gen; // 乱数生成器 | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif // !PAX_SAPIENTICA_GROUP_SIMULATOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.