1
1
package bwta ;
2
2
3
3
import bwapi .Position ;
4
+ import bwapi .WalkPosition ;
4
5
import bwem .ChokePoint ;
5
6
import bwapi .Pair ;
6
- import bwapi .Pair ;
7
+
8
+ import java .util .List ;
7
9
8
10
9
11
public class Chokepoint {
@@ -13,15 +15,10 @@ public class Chokepoint {
13
15
private double width ;
14
16
15
17
Chokepoint (final ChokePoint chokePoint ) {
16
- try {
17
- this .chokePoint = chokePoint ;
18
- this .sides = new Pair <>(chokePoint .getGeometry ().get (1 ).toPosition (), chokePoint .getGeometry ().get (2 ).toPosition ());
19
- this .center = chokePoint .getGeometry ().get (0 ).toPosition ();
20
- this .width = sides .getLeft ().getDistance (sides .getRight ());
21
- }
22
- catch (Exception e ) {
23
- System .out .println (width );
24
- }
18
+ this .chokePoint = chokePoint ;
19
+ this .sides = calculateSides (chokePoint .getGeometry ());
20
+ this .center = sides .getFirst ().add (sides .getSecond ()).divide (2 );
21
+ this .width = sides .getLeft ().getDistance (sides .getRight ());
25
22
}
26
23
27
24
public Pair <Region , Region > getRegions () {
@@ -52,4 +49,22 @@ public boolean equals(final Object o) {
52
49
public int hashCode () {
53
50
return chokePoint .hashCode ();
54
51
}
52
+
53
+ private static Pair <Position , Position > calculateSides (final List <WalkPosition > wp ) {
54
+ WalkPosition p1 = wp .get (0 );
55
+ WalkPosition p2 = wp .get (0 );
56
+ double d_max = -1 ;
57
+
58
+ for (int i =0 ; i < wp .size (); i ++) {
59
+ for (int j =i +1 ; j < wp .size (); j ++) {
60
+ double d = wp .get (i ).getDistance (wp .get (j ));
61
+ if (d > d_max ) {
62
+ d_max = d ;
63
+ p1 = wp .get (i );
64
+ p2 = wp .get (j );
65
+ }
66
+ }
67
+ }
68
+ return new Pair <>(p1 .toPosition (), p2 .toPosition ());
69
+ }
55
70
}
0 commit comments