forked from Swarm-IITKgp/SimpleSwarmSimulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
104 lines (81 loc) · 1.91 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "SwarmBot.h"
#include <bits/stdc++.h>
#include <unistd.h>
#include "Motion.h"
#include "Communication.h"
using namespace std;
int BOT_ID;
int main(int argcs, char** argv){
SwarmBot v;
Points p;
vector<SwarmBot>bots;
vector<Points> pts;
map<int,Points> mp;
int *d,*key,j;
BOT_ID=atoi(argv[1]);
d=(int*)malloc(pts.size()*sizeof(int));
key=(int*)malloc(pts.size()*sizeof(int));
pts=getAllDest();
bots=getAllPose();
for(int i=0;i<pts.size();i++){
mp[i]=pts[i];
}
cout<<BOT_ID<<endl;
for(j=0;j<=BOT_ID;j++){
for(int i = 0; i <pts.size()-1 ; ++i){
d[i] = (pts[i].x - bots[j].x)*(pts[i].x - bots[j].x)+(pts[i].y - bots[j].y)*(pts[i].y - bots[j].y);
if(i != 0){
if(d[i]<d[0]){
int swap=d[i];
d[i]=d[0];
d[0]=swap;
key[j]=i;
mp[j]=pts[i];
}
}
else{
key[j]=i;
mp[j]=pts[i];
}
} cout<<pts.size()<<" "<<key[j]<<endl;
pts.erase(pts.begin()+key[j]);
//if(j==3||j==2)
cout<<"hi"<<j<<" "<<pts.size()<<" "<<mp[j].x<<" "<<mp[j].y<<endl;
}
while(true){
pts=getAllDest();
run( BOT_ID , 10 , mp[BOT_ID].x , mp[BOT_ID].y , 180 );
}
/*while( true ){
bots=getAllPose();
for(int i=0; i < pts.size() ; i++){
d[i] = (pts[i].x - bots[BOT_ID].x)*(pts[i].x - bots[BOT_ID].x)+(pts[i].y - bots[BOT_ID].y)*(pts[i].y - bots[BOT_ID].y);
if(i!=0){
if(d[i]<d[0]){
int swap=d[i];
d[i]=d[0];
d[0]=swap;
key=i;
}
}
else
key=0;
}
run( BOT_ID , 10 , pts[key].x , pts[key].y , 180 );
//pts.erase(pts.begin()+key);
//move(BOT_ID, 10, 75.0, 50.0);
//if(bots[BOT_ID].x>30&&bots[BOT_ID].y>100)
/*if( BOT_ID > 0)
{
//while(i<bots.size()){
//if(bots[0].x>bots[BOT_ID].x)
run( BOT_ID , 10 , pts[BOT_ID].x , pts[BOT_ID].y , 180 );
//else
// run(BOT_ID,10,300,300,180);
}
else
run( BOT_ID , 10 , pts[BOT_ID].x , pts[BOT_ID].y , 180 );
*/
//}
return 0;
}