Skip to content

Commit bbfd211

Browse files
committed
fix wrong ChokeSides implementation to something reasonable
1 parent d6c09f3 commit bbfd211

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/main/java/bwta/BWTA.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@
1414

1515
public class BWTA {
1616
private static BWEM bwem;
17-
private static Game game;
1817
static Map<Area, Region> regionMap;
1918
static Map<ChokePoint, Chokepoint> chokeMap;
2019
static Map<Base, BaseLocation> baseMap;
2120
private static Set<Region> regions;
2221
private static Set<Chokepoint> chokepoints;
2322
private static Set<BaseLocation> baseLocations;
2423

25-
public static void readMap(final Game gamePointer) {
26-
game = gamePointer;
24+
public static void readMap(final Game game) {
2725
bwem = new BWEM(game);
2826
}
2927

src/main/java/bwta/Chokepoint.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package bwta;
22

33
import bwapi.Position;
4+
import bwapi.WalkPosition;
45
import bwem.ChokePoint;
56
import bwapi.Pair;
6-
import bwapi.Pair;
7+
8+
import java.util.List;
79

810

911
public 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

Comments
 (0)