From fea3a0eed32db67ef435e7317727ca27f93ae31a Mon Sep 17 00:00:00 2001 From: SemperVinco Date: Wed, 1 Mar 2017 23:51:26 +0100 Subject: include heading in -p option, pair -> tuple --- main.cpp | 10 +++++----- world.cpp | 9 +++++---- world.h | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 1f41077..3072f57 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -219,7 +219,7 @@ int main(int argc,char **argv){ vector teams; bool opt_pos = false; - vector> positions; + vector> positions; int k = 1; // Increase past options; @@ -233,14 +233,14 @@ int main(int argc,char **argv){ assert(f); teams.push_back(assemble(preprocess(f))); if(opt_pos) { - positions.emplace_back((int)strtol(argv[i+1],NULL,10), (int)strtol(argv[i+2],NULL,10)); // TODO: check if i>argc - i += 2; + positions.emplace_back((int)strtol(argv[i+1],NULL,10), (int)strtol(argv[i+2],NULL,10), (int)strtol(argv[i+3],NULL,10)); // TODO: check if i>argc + i += 3; } } for(int i=0; i<(int)teams.size(); i++) { const Team &t = teams[i]; - Robot &r = opt_pos ? world.create(&t,2,t.banks.size(),false, positions[i].first, positions[i].second) + Robot &r = opt_pos ? world.create(&t,2,t.banks.size(),false, get<0>(positions[i]), get<1>(positions[i]), get<2>(positions[i])) : world.create(&t,2,t.banks.size(),false); for(int i=0;i<(int)t.banks.size();i++){ diff --git a/world.cpp b/world.cpp index 17e63a2..b74e7cb 100644 --- a/world.cpp +++ b/world.cpp @@ -232,17 +232,18 @@ World::~World(){ } Robot& World::create(const Team *team,int iset,int nbanks,bool mobile){ - int x,y; + int x,y,heading; while(true){ x=rand()%SIZE; y=rand()%SIZE; if(!board[y][x])break; } + heading = rand()%4; - return create(team, iset, nbanks, mobile, x, y); + return create(team, iset, nbanks, mobile, x, y, heading); } -Robot& World::create(const Team *team,int iset,int nbanks,bool mobile,int x,int y){ +Robot& World::create(const Team *team,int iset,int nbanks,bool mobile,int x,int y,int heading){ x = (x%SIZE + SIZE)%SIZE; // Negative values are wrapped y = (y%SIZE + SIZE)%SIZE; assert(!board[y][x]); @@ -251,7 +252,7 @@ Robot& World::create(const Team *team,int iset,int nbanks,bool mobile,int x,int board[y][x]->banks.resize(nbanks); board[y][x]->iset=iset; board[y][x]->mobile=mobile; - board[y][x]->heading=rand()%4; + board[y][x]->heading=heading%4; return *board[y][x]; } diff --git a/world.h b/world.h index 90ca74e..e964e8d 100644 --- a/world.h +++ b/world.h @@ -94,7 +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& create(const Team *team,int iset,int nbanks,bool mobile,int x,int y,int heading); Robot& createInFront(const Robot *caller,const Team *team,int iset,int nbanks,bool mobile); void tick(); -- cgit v1.2.3-70-g09d2