Skip to content

Commit

Permalink
Add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
batman-nair committed Nov 17, 2019
1 parent 821d3d3 commit 07000eb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
*~
build/*
ptrain
ircis
*.log
35 changes: 35 additions & 0 deletions src/Ircis.cc
@@ -0,0 +1,35 @@
#include <Ircis.h>

namespace Ircis {
bool Ircis::update() {
bool keep_moving = false;
for (auto it = runner_list_.begin(); it != runner_list_.end(); ++it) {
if (it->step()) {
Logger::log_line("Runner ", it->get_id(), " updated.");
keep_moving = true;
}
else {
Logger::log_line("Runner ", it->get_id(), " died.");
it->run_debug();
runner_list_.erase(it--); /* iter-- so the loop proceeds properly */
}
}

while (!new_runners_list_->empty()) {
Logger::log_line("Adding new Runner");
keep_moving = true;
auto new_runner_info = new_runners_list_->front();
Logger::log_line("Got new runner info", runner_id_);
runner_list_.emplace_back(runner_id_++, new_runner_info.position, grid_, log_, new_runners_list_, new_runner_info.st);
Logger::log_line("Added new runner to list", runner_id_);
new_runners_list_->pop();
Logger::log_line("New runner added by ");
}

if (!keep_moving) {
log_->print_line(" ");
Logger::log_line_dbg("Ircis has finished running!");
}
return keep_moving;
}
}
34 changes: 34 additions & 0 deletions src/Ircis.h
@@ -0,0 +1,34 @@
#pragma once

#include <Logger.h>
#include <Grid.h>
#include <Runner.h>

#include <string>
#include <queue>
#include <memory>

namespace Ircis {
class Ircis {
public:
Ircis(std::string file_name)
:runner_id_(0), grid_(std::make_shared<Grid>(file_name)),
log_(std::make_shared<Logger>("output.log")),
new_runners_list_(std::make_shared<std::queue<RunnerInfo> >()) {
runner_list_.emplace_back(runner_id_++, grid_, log_, new_runners_list_);
}

// Steps all runner instances
// Returns false when all runners are dead
// (woah that sounds dark)
bool update();

private:
int runner_id_;
std::shared_ptr<Grid> grid_;
std::shared_ptr<Logger> log_;
std::vector<Runner> runner_list_;

std::shared_ptr<std::queue<RunnerInfo> > new_runners_list_;
};
}

0 comments on commit 07000eb

Please sign in to comment.