diff options
-rw-r--r-- | main.cpp | 25 | ||||
-rw-r--r-- | sim.exe | bin | 0 -> 1065189 bytes | |||
-rw-r--r-- | world.cpp | 8 | ||||
-rw-r--r-- | world.h | 1 |
4 files changed, 31 insertions, 3 deletions
@@ -4,6 +4,7 @@ #include <string> #include <unordered_map> #include <cstdlib> +#include <array> #include <cctype> #include <cassert> #include <sys/time.h> @@ -215,14 +216,32 @@ int main(int argc,char **argv){ World world; vector<Team> teams; - for(int i=1;i<argc;i++){ + + bool opt_pos = false; + vector<array<int,2>> positions; // TODO: use pair? + + int k = 1; // Increase past options; + + if(string(argv[k]) == "-p") { + opt_pos = true; + k++; + } + + for(int i=k;i<argc;i++){ // Start after options ifstream f(argv[i]); assert(f); teams.push_back(assemble(preprocess(f))); + if(opt_pos) { + positions.push_back({strtol(argv[i+1],NULL,10), strtol(argv[i+2],NULL,10)}); // TODO: check if i>argc + i += 2; + } } - for(const Team &t : teams){ - Robot &r=world.create(&t,2,t.banks.size(),false); + for(int i=0; i<teams.size(); i++) { + const Team &t = teams[i]; + Robot &r = opt_pos ? world.create(&t,2,t.banks.size(),false, positions[i][0], positions[i][1]) + : world.create(&t,2,t.banks.size(),false); + for(int i=0;i<(int)t.banks.size();i++){ r.load(i,t.banks[i]); r.active=1; Binary files differ@@ -234,6 +234,14 @@ Robot& World::create(const Team *team,int iset,int nbanks,bool mobile){ y=rand()%SIZE; if(!board[y][x])break; } + + return create(team, iset, nbanks, mobile, x, y); +} + +Robot& World::create(const Team *team,int iset,int nbanks,bool mobile,int x,int y){ + x = (x%SIZE + SIZE)%SIZE; // Negative values are wrapped + y = (y%SIZE + SIZE)%SIZE; + assert(!board[y][x]); board[y][x]=new Robot(); board[y][x]->team=team; board[y][x]->banks.resize(nbanks); @@ -94,6 +94,7 @@ public: ~World(); Robot& create(const Team *team,int iset,int nbanks,bool mobile); + Robot& create(const Team *team,int iset,int nbanks,bool mobile,int x,int y); Robot& createInFront(const Robot *caller,const Team *team,int iset,int nbanks,bool mobile); void tick(); |