-
Notifications
You must be signed in to change notification settings - Fork 1
/
World.h
57 lines (44 loc) · 1.49 KB
/
World.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef WORLD_H
#define WORLD_H
#include "emp/Evolve/World.hpp"
#include "Org.h"
class OrgWorld : public emp::World<Organism> {
emp::Random &random;
std::vector<emp::WorldPosition> reproduce_queue;
public:
OrgWorld(emp::Random &_random) : emp::World<Organism>(_random), random(_random) { }
~OrgWorld() {}
const pop_t &GetPopulation() { return pop;}
void Update() {
emp::World<Organism>::Update();
//Process each organism
emp::vector<size_t> schedule = emp::GetPermutation(random, GetSize());
for(int i : schedule) {
if(!IsOccupied(i)) {continue;}
pop[i]->Process(i);
}
//Time to allow reproduction for any organisms that ran the reproduce instruction
for (emp::WorldPosition location : reproduce_queue) {
if (!IsOccupied(location)) {
return;
}
std::optional<Organism> offspring =
pop[location.GetIndex()]->CheckReproduction();
if (offspring.has_value()) {
DoBirth(offspring.value(), location.GetIndex());
}
}
reproduce_queue.clear();
}
void CheckOutput(float output, OrgState &state) {
//TODO: Check if the organism solved a task!
}
void ReproduceOrg(emp::WorldPosition location) {
// Wait until after all organisms have been processed to perform
// reproduction. If reproduction happened immediately then the child could
// ovewrite the parent, and then we would be running the code of a deleted
// organism
reproduce_queue.push_back(location);
}
};
#endif