Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
821d3d3
commit 07000eb
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
*~ | ||
build/* | ||
ptrain | ||
ircis | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_; | ||
}; | ||
} |