Skip to content

Commit

Permalink
Merge pull request #47 from AsPJT/feature/guinpen98/add-settlement
Browse files Browse the repository at this point in the history
集落を追加
  • Loading branch information
guinpen98 authored Sep 18, 2023
2 parents 134eff4 + 651a601 commit 155df74
Show file tree
Hide file tree
Showing 21 changed files with 583 additions and 31 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/reviewdog-cpplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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\
"
5 changes: 3 additions & 2 deletions Library/PAX_SAPIENTICA/Simulation/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ namespace paxs {
using Vector2 = paxs::Vector2<GridType>;
using Environment = paxs::Environment<GridType>;

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<Environment> env) noexcept
: Object<GridType>(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<Environment> env) noexcept
: Object<GridType>(id, name, pos), gender(gen), age(age), life_span(life_span), environment(env) {}

/// @brief Move the agent.
/// @brief エージェントを移動させる
Expand Down
66 changes: 66 additions & 0 deletions Library/PAX_SAPIENTICA/Simulation/BaseGroup.hpp
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
52 changes: 52 additions & 0 deletions Library/PAX_SAPIENTICA/Simulation/BasicGroup.hpp
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
42 changes: 42 additions & 0 deletions Library/PAX_SAPIENTICA/Simulation/CompositeSettlement.hpp
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
60 changes: 60 additions & 0 deletions Library/PAX_SAPIENTICA/Simulation/GroupSimulator.hpp
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
7 changes: 4 additions & 3 deletions Library/PAX_SAPIENTICA/Simulation/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ namespace paxs {
public:
using Vector2 = paxs::Vector2<GridType>;

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; }
Expand Down Expand Up @@ -62,7 +63,7 @@ namespace paxs {
}

protected:
std::string id; // オブジェクトのID
std::uint_least32_t id; // オブジェクトのID
std::string name; // オブジェクトの名前
Vector2 position; // オブジェクトの座標
};
Expand Down
Loading

0 comments on commit 155df74

Please sign in to comment.