From 9cf8a275cc6efb10dcbb342e71ddedaf45f73ae2 Mon Sep 17 00:00:00 2001 From: wanotaitei Date: Wed, 22 May 2024 19:46:54 +0900 Subject: [PATCH] add: Farming and HunterGatherer --- .../PAX_SAPIENTICA/Simulation/Settlement.hpp | 46 ++++++++++--------- .../Simulation/SettlementAgent.hpp | 32 +++++++++++-- .../Simulation/SettlementSimulator.hpp | 9 +++- 3 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp index 05c7f17c1..043b197ef 100644 --- a/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/Settlement.hpp @@ -243,10 +243,10 @@ namespace paxs { Agent male_ = close_settlements[j].getAgentCopy(male_id); Agent& female_ = agents[marriageable_female_index[index_pair.first]]; - female_.marry(male_id, male_.cgetGenomePtr()); + female_.marry(male_id, male_.cgetGenomePtr(), male_.cgetFarming(), male_.cgetHunterGatherer()); const std::uint_least64_t female_id = female_.getId(); - male_.marry(female_id, female_.cgetGenomePtr()); + male_.marry(female_id, female_.cgetGenomePtr(), female_.cgetFarming(), female_.cgetHunterGatherer()); agents.emplace_back(male_); is_found = true; @@ -396,7 +396,9 @@ namespace paxs { 0, // TODO: 名前ID 0, kanakuma_life_span.setLifeSpan(genome.getGender(), *gen), - genome + genome, + (((*gen)() % 2) == 0) ? agent.cgetFarming() : agent.cgetPartnerFarming(), + (((*gen)() % 2) == 0) ? agent.cgetHunterGatherer() : agent.cgetPartnerHunterGatherer() )); } } @@ -414,24 +416,26 @@ namespace paxs { /// @brief Emigration. /// @brief 渡来 void emigration(KanakumaLifeSpan& kanakuma_life_span, std::uint_least64_t& count) noexcept { - //if (agents.size() >= 60) { - - // const std::uint_least8_t set_gender = static_cast(gender_dist(*gen)); - // const std::uint_least32_t set_lifespan = kanakuma_life_span.setAdultLifeSpan(set_gender, *gen); - - // std::uniform_int_distribution<> lifespan_dist{ - // (std::min)(18 * SimulationConstants::getInstance()->steps_per_year + 1, static_cast(set_lifespan - 1)), - // static_cast(set_lifespan - 1) }; // 性別の乱数分布 - - // agents.emplace_back(Agent( - // UniqueIdentification::generate(), - // 0, // TODO: 名前ID - // set_gender, - // lifespan_dist(*gen), - // set_lifespan - // )); - // ++count; - //} + if (agents.size() >= 60) { + + Genome genome = Genome::generateRandom(); + const std::uint_least32_t set_lifespan = kanakuma_life_span.setLifeSpan(genome.getGender(), *gen); + + std::uniform_int_distribution<> lifespan_dist{ + (std::min)(18 * SimulationConstants::getInstance()->steps_per_year + 1, static_cast(set_lifespan - 1)), + static_cast(set_lifespan - 1) }; // 性別の乱数分布 + + agents.emplace_back(Agent( + UniqueIdentification::generate(), + 0, // TODO: 名前ID + lifespan_dist(*gen), + set_lifespan, + genome, + 255, // ((gen() % 2) == 0) ? agent.cgetFarming() : agent.cgetPartnerFarming(), + 0 // ((gen() % 2) == 0) ? agent.cgetHunterGatherer() : agent.cgetPartnerHunterGatherer() + )); + ++count; + } } /// @brief Age update. diff --git a/Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp b/Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp index 18ef2d41b..f811dc2bc 100644 --- a/Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp @@ -38,8 +38,12 @@ namespace paxs { SettlementAgent() = default; explicit SettlementAgent(const std::uint_least64_t id, const std::uint_least32_t& name_id, - const std::uint_least32_t age, const std::uint_least32_t life_span, const Genome& genome) noexcept - : id(id), name_id(name_id), gender(genome.getGender()), age(age), life_span(life_span), genome(genome) {} + const std::uint_least32_t age, const std::uint_least32_t life_span, const Genome& genome, + std::uint_least8_t farming_, // 農耕文化 + std::uint_least8_t hunter_gatherer_ // 狩猟採集文化 + ) noexcept + : id(id), name_id(name_id), gender(genome.getGender()), age(age), life_span(life_span), genome(genome), + farming(farming_), hunter_gatherer(hunter_gatherer_) {} /// @brief Get the id. /// @brief idを取得 @@ -79,6 +83,14 @@ namespace paxs { constexpr const Genome& cgetPartnerGenome() const noexcept { return *partner_genome; } + constexpr std::uint_least8_t cgetFarming() const noexcept { return farming; } + + constexpr std::uint_least8_t cgetHunterGatherer() const noexcept { return hunter_gatherer; } + + constexpr std::uint_least8_t cgetPartnerFarming() const noexcept { return partner_farming; } + + constexpr std::uint_least8_t cgetPartnerHunterGatherer() const noexcept { return partner_hunter_gatherer; } + constexpr bool operator==(const SettlementAgent& a) const noexcept { return id == a.id && name_id == a.name_id && @@ -88,6 +100,8 @@ namespace paxs { genome == a.genome && partner_id == a.partner_id && partner_genome == a.partner_genome; + partner_farming == a.partner_farming; + partner_hunter_gatherer == a.partner_hunter_gatherer; } /// @brief Is the agent married? @@ -96,10 +110,15 @@ namespace paxs { /// @brief Set the agent's marriage status. /// @brief 結婚する - void marry(const std::uint_least64_t partner_id_, const Genome* partner_genome_) noexcept { + void marry(const std::uint_least64_t partner_id_, const Genome* partner_genome_, + std::uint_least8_t partner_farming_, // 結婚相手の農耕文化 + std::uint_least8_t partner_hunter_gatherer_ // 結婚相手の狩猟採集文化 + ) noexcept { is_married = true; partner_id = partner_id_; partner_genome = partner_genome_; + partner_farming = partner_farming_; + partner_hunter_gatherer = partner_hunter_gatherer_; } /// @brief Is the agent able to marry? @@ -133,6 +152,8 @@ namespace paxs { is_married = false; partner_id = 0; partner_genome = nullptr; + partner_farming = 0; + partner_hunter_gatherer = 0; } std::uint_least8_t getBirthIntervalCount() const noexcept { return birth_interval_count; } @@ -144,6 +165,11 @@ namespace paxs { std::uint_least8_t gender; // 性別: 0 -> 女性, 1 -> 男性 std::uint_least8_t birth_interval_count = 0; // 出産の間隔のカウント + std::uint_least8_t farming = 0; // 農耕文化 + std::uint_least8_t hunter_gatherer = 0; // 狩猟採集文化 + std::uint_least8_t partner_farming = 0; // 結婚相手の農耕文化 + std::uint_least8_t partner_hunter_gatherer = 0; // 結婚相手の狩猟採集文化 + std::uint_least32_t age; // 年齢 std::uint_least32_t life_span; // 寿命 std::uint_least32_t name_id; // 名前のID diff --git a/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp b/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp index 946f9c9d1..90cd24ec6 100644 --- a/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp +++ b/Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp @@ -333,7 +333,10 @@ namespace paxs { 0, // TODO: 名前ID lifespan_dist(gen), set_lifespan, - genome), static_cast(i)); + genome, + 0, // ((gen() % 2) == 0) ? agent.cgetFarming() : agent.cgetPartnerFarming(), + 255 // ((gen() % 2) == 0) ? agent.cgetHunterGatherer() : agent.cgetPartnerHunterGatherer() + ), static_cast(i)); } // 令制国の人口を減らす @@ -383,7 +386,9 @@ namespace paxs { 0, // TODO: 名前ID lifespan_dist(gen), set_lifespan, - genome + genome, + 0, // ((gen() % 2) == 0) ? agent.cgetFarming() : agent.cgetPartnerFarming(), + 255 // ((gen() % 2) == 0) ? agent.cgetHunterGatherer() : agent.cgetPartnerHunterGatherer() ); } settlement.addAgents(agents);