aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSemperVinco <w.deweijer@hotmail.com>2017-03-01 22:24:57 +0100
committerSemperVinco <w.deweijer@hotmail.com>2017-03-01 22:24:57 +0100
commit0bf7fd38aea996a381717fe4be09817259575531 (patch)
tree65c76252bb4b42402ca7ff0eb103573b542b0347
parent2148f4e5d4effa5d1613a074f91da2c34ac6e5ed (diff)
Add position argument option -p which places bots in specific locations, syntax: ./sim -p b1.rob 1 2 b2.rob -2 4
-rw-r--r--main.cpp25
-rw-r--r--sim.exebin0 -> 1065189 bytes
-rw-r--r--world.cpp8
-rw-r--r--world.h1
4 files changed, 31 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index 36f5580..30002a8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -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;
diff --git a/sim.exe b/sim.exe
new file mode 100644
index 0000000..9d4fa7d
--- /dev/null
+++ b/sim.exe
Binary files differ
diff --git a/world.cpp b/world.cpp
index 86c805e..b1d5e75 100644
--- a/world.cpp
+++ b/world.cpp
@@ -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);
diff --git a/world.h b/world.h
index 8f17834..90ca74e 100644
--- a/world.h
+++ b/world.h
@@ -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();