diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-03-01 20:12:04 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-03-01 20:12:04 +0100 |
commit | b0c5387e66f23199191feac71930db412762406d (patch) | |
tree | 9bc6cad0aaf686b0cfe75463b9866dcd8d49700e | |
parent | 8a3ba59193b0487fdffa4dc05abd4487b1ebf7fb (diff) |
Print world during simulation
-rw-r--r-- | main.cpp | 4 | ||||
-rw-r--r-- | world.cpp | 15 | ||||
-rw-r--r-- | world.h | 2 |
3 files changed, 19 insertions, 2 deletions
@@ -229,7 +229,11 @@ int main(int argc,char **argv){ } } + world.print(); for(int i=0;i<C::autoTimeout;i++){ world.tick(); + cin.get(); + cout<<"\x1B[2J\x1B[H"; + world.print(); } } @@ -48,7 +48,7 @@ uint16_t* Robot::resolveVar(const Argument &arg,World &world){ Instruction Robot::resolve(World &world){ Instruction ins=banks.at(ip.bank).at(ip.pos); - cout<<this<<" Resolving "<<ins<<endl; + // cout<<this<<" Resolving "<<ins<<endl; vector<bool> dstvar(ins.args.size(),false); if(ins.op==ins_t::set||ins.op==ins_t::add||ins.op==ins_t::sub||ins.op==ins_t::scan){ assert(dstvar.size()>0); @@ -112,7 +112,7 @@ int Robot::calcDuration(Instruction &ins){ } WorldAction Robot::execute(Instruction &ins,World &world){ - cout<<this<<" Executing "<<ins<<endl; + // cout<<this<<" Executing "<<ins<<endl; WorldAction action=WorldAction::none; switch(ins.op){ case ins_t::set:{ @@ -303,6 +303,17 @@ Robot* World::targetbot(const Robot *r){ return *targetbotptr(r); } +void World::print() const { + for(int y=0;y<SIZE;y++){ + for(int x=0;x<SIZE;x++){ + if(board[y][x]==nullptr)cout<<".."; + else cout<<string(2,"^>v<"[board[y][x]->heading%4]); + cout<<' '; + } + cout<<endl; + } +} + ostream& operator<<(ostream &os,const Argument &arg){ if(arg.remote){ @@ -98,6 +98,8 @@ public: void tick(); Robot* targetbot(const Robot *r); + + void print() const; }; |