Skip to content

Commit

Permalink
add: Farming and HunterGatherer
Browse files Browse the repository at this point in the history
  • Loading branch information
AsPJT committed May 22, 2024
1 parent 9502fcc commit 9cf8a27
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 26 deletions.
46 changes: 25 additions & 21 deletions Library/PAX_SAPIENTICA/Simulation/Settlement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
));
}
}
Expand All @@ -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<std::uint_least8_t>(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<int>(set_lifespan - 1)),
// static_cast<int>(set_lifespan - 1) }; // 性別の乱数分布

// agents.emplace_back(Agent(
// UniqueIdentification<std::uint_least64_t>::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<int>(set_lifespan - 1)),
static_cast<int>(set_lifespan - 1) }; // 性別の乱数分布

agents.emplace_back(Agent(
UniqueIdentification<std::uint_least64_t>::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.
Expand Down
32 changes: 29 additions & 3 deletions Library/PAX_SAPIENTICA/Simulation/SettlementAgent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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を取得
Expand Down Expand Up @@ -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 &&
Expand All @@ -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?
Expand All @@ -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?
Expand Down Expand Up @@ -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; }
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions Library/PAX_SAPIENTICA/Simulation/SettlementSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ namespace paxs {
0, // TODO: 名前ID
lifespan_dist(gen),
set_lifespan,
genome), static_cast<std::size_t>(i));
genome,
0, // ((gen() % 2) == 0) ? agent.cgetFarming() : agent.cgetPartnerFarming(),
255 // ((gen() % 2) == 0) ? agent.cgetHunterGatherer() : agent.cgetPartnerHunterGatherer()
), static_cast<std::size_t>(i));
}

// 令制国の人口を減らす
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9cf8a27

Please sign in to comment.