-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sim.cpp
67 lines (52 loc) · 1.44 KB
/
Sim.cpp
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
58
59
60
61
62
63
64
65
//
// Created by jan on 14.09.17.
//
#include "Sim.h"
#include <iostream>
#define INPUT_NEURON_COUNT 4
#define OUTPUT_NEURON_COUNT 2
class Specimen;
Sim::Sim(World& world, int specimen_start_count, int food_count) : world(world)
{
this->specimen_start_count = specimen_start_count;
input_neurons.resize(specimen_start_count);
output_neurons.resize(specimen_start_count);
for(int i = 0; i<specimen_start_count; i++)
{
input_neurons[i].resize(INPUT_NEURON_COUNT);
output_neurons[i].resize(OUTPUT_NEURON_COUNT);
output_neurons[i][0] = 1-((float) rand() * 2)/RAND_MAX;
output_neurons[i][1] = 1-((float) rand() * 2)/RAND_MAX;
specimen.push_back(Specimen(input_neurons[i], output_neurons[i], world));
}
for(int i = 0; i<food_count; i++)
{
food.push_back(Food(world));
}
}
void Sim::simulate_frame()
{
for(int i = 0; i<specimen.size(); i++)
{
if(specimen[i].is_active())
{
specimen[i].simulate_frame();
if(!specimen[i].is_active())
{
//netManager.kill(i);
}
}
}
//std::cout<<specimen[0].get_food_level()<<" "<<specimen[0].get_life_time_equivalent()<<"\n";
//calculate the nets or some shit here
}
std::vector <Specimen> Sim::get_specimens()
{
return specimen;
}
std::vector<Food> Sim::get_food() {
return food;
}
World &Sim::get_world() const {
return world;
}