11package bwta ;
22
33import bwapi .Position ;
4+ import bwapi .WalkPosition ;
45import bwem .ChokePoint ;
56import bwapi .Pair ;
6- import bwapi .Pair ;
7+
8+ import java .util .List ;
79
810
911public class Chokepoint {
@@ -13,15 +15,10 @@ public class Chokepoint {
1315 private double width ;
1416
1517 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 ());
2522 }
2623
2724 public Pair <Region , Region > getRegions () {
@@ -52,4 +49,22 @@ public boolean equals(final Object o) {
5249 public int hashCode () {
5350 return chokePoint .hashCode ();
5451 }
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+ }
5570}
0 commit comments