forked from stefano-1981/vacuum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.cc
35 lines (29 loc) · 905 Bytes
/
simulation.cc
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
#include "simulation.h"
#include <iostream>
Simulation::Simulation(const Map& map) : time_left_(100),
battery_(100),
agent_(&battery_, &time_left_),
map_(map) {}
void Simulation::Run() {
while (time_left_ > 0 && agent_.IsAlive()) {
// Get the agent action based on the perception.
const Perception& perception = map_.GetAgentPerception();
Direction action = agent_.NextDirection(perception);
// Update all things.
map_.Update(action);
if (map_.AgentAtHome()) {
battery_.Charge();
}
--time_left_;
battery_.Use();
map_.Print();
}
}
float Simulation::GetAgentScore() {
float score = map_.CleanedRatio() * 0.5;
std::cout << map_.CleanedRatio() << std::endl;
if (map_.AgentAtHome()) {
score += 0.5;
}
return score;
}