diff options
-rw-r--r-- | sim.cpp | 49 |
1 files changed, 39 insertions, 10 deletions
@@ -48,7 +48,7 @@ int parseInt(const char *str){ } void usage(char **argv){ - cerr<<"Usage: "<<argv[0]<<" [-r <fname>]* [-p <fname> <x> <y> <heading>]* [-s <sleeptime>] [-t]"<<endl; + cerr<<"Usage: "<<argv[0]<<" [-r <fname>]* [-p <fname> <x> <y> <heading>]* [-s <sleeptime>] [-t] [-B]"<<endl; } int main(int argc,char **argv){ @@ -62,6 +62,7 @@ int main(int argc,char **argv){ vector<RobotSpec> robotSpecs; int sleeptime=3000; bool step = false; + bool batch = false; if(argc<=1){ usage(argv); @@ -109,6 +110,10 @@ int main(int argc,char **argv){ step = true; break; + case 'B': + batch = true; + break; + default: cerr<<"Unknown switch in '"<<argv[i]<<"'"<<endl; return 1; @@ -131,19 +136,43 @@ int main(int argc,char **argv){ } } - sb=new ScreenBuffer(SIZE*3, SIZE+1); + if(batch){ + for(int i=0;i<C::autoTimeout;i++){ + world.tick(); + bool haveActive=false; + for(int j=0;j<SIZE*SIZE;j++){ + const int x=j%SIZE,y=j/SIZE; + if(world.board[y][x]&&world.board[y][x]->active){ + haveActive=true; + break; + } + } + if(!haveActive)break; + } + for(int y=0;y<SIZE;y++){ + for(int x=0;x<SIZE;x++){ + if(world.board[y][x]){ + cout<<world.board[y][x]->team<<' ' + <<x<<' '<<y<<' ' + <<world.board[y][x]->heading<<endl; + } + } + } + } else { + sb=new ScreenBuffer(SIZE*3, SIZE+1); #ifndef _WIN32 - signal(SIGINT,signalHandler); + signal(SIGINT,signalHandler); #endif - world.print(*sb); - sb->draw(); - for(int i=0;i<C::autoTimeout;i++){ - if(step) cin.get(); - else usleep(sleeptime); - world.tick(); world.print(*sb); - sb->mvprintf(0, SIZE, "step: %5i", i+2); sb->draw(); + for(int i=0;i<C::autoTimeout;i++){ + if(step)cin.get(); + else usleep(sleeptime); + world.tick(); + world.print(*sb); + sb->mvprintf(0, SIZE, "step: %5i", i+2); + sb->draw(); + } } delete sb; } |