-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.java
More file actions
40 lines (34 loc) · 1.02 KB
/
Map.java
File metadata and controls
40 lines (34 loc) · 1.02 KB
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
import java.util.*;
class Map {
static final double width = 40000.0;
static double height = 20000.0;
static final double CPT_RADIUS = 1500.0;
static final double POD_RADIUS = 250.0;
static final double OBS_RADIUS = 1000.0;
Unit[] cp;
Unit[] obs;
Map() {
createCpt();
createObs();
}
void createObs() {}
void createCpt() {
int num = 3 + (int)(Math.random()*4);
cp = new Unit[num];
for (int i = 0; i < num; i++) {
cp[i] = getNewCp(i);
}
}
Unit getNewCp(int i) {
outer:
while (true) {
double x = CPT_RADIUS*6.0 + Math.random()*(width-CPT_RADIUS*10.0);
double y = CPT_RADIUS*4.0 + Math.random()*(height-CPT_RADIUS*8.0);
Unit u = new Unit(x,y,CPT_RADIUS);
for (int j = 0; j < i; j++) {
if (u.distance(cp[j]) < 4*CPT_RADIUS) continue outer;
}
return u;
}
}
}