Skip to content

Commit 1f1d242

Browse files
committed
Fix BWEM chokepoint identity for parallel passages
1 parent 0507796 commit 1f1d242

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

‎src/main/java/bwem/ChokePoint.java‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,25 +313,14 @@ public boolean equals(final Object object) {
313313
return false;
314314
} else {
315315
final ChokePoint that = (ChokePoint) object;
316-
final boolean lel = this.areas.getLeft().equals(that.areas.getLeft());
317-
final boolean ler = this.areas.getLeft().equals(that.areas.getRight());
318-
final boolean rer = this.areas.getRight().equals(that.areas.getRight());
319-
final boolean rel = this.areas.getRight().equals(that.areas.getLeft());
320-
return lel && rer
321-
|| ler && rel; /* true if area pairs are an exact match or if one pair is reversed. */
316+
// Parallel connections can share areas or even a center, but not a graph/index.
317+
return this.graph == that.graph && this.index == that.index;
322318
}
323319
}
324320

325321
@Override
326322
public int hashCode() {
327-
int idLeft = areas.getLeft().getId().intValue();
328-
int idRight = areas.getRight().getId().intValue();
329-
if (idLeft > idRight) {
330-
final int idLeftTmp = idLeft;
331-
idLeft = idRight;
332-
idRight = idLeftTmp;
333-
}
334-
return Objects.hash(idLeft, idRight);
323+
return Objects.hash(graph, index);
335324
}
336325

337326
/**

‎src/test/java/bwapi/BWEMTest.java‎

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
import bwem.BWEM;
44
import bwem.BWMap;
5+
import bwta.BWTA;
6+
import bwta.Chokepoint;
7+
import bwta.Region;
58
import org.junit.Test;
69

710
import java.io.IOException;
11+
import java.util.Collections;
812
import java.util.HashMap;
13+
import java.util.HashSet;
14+
import java.util.List;
915
import java.util.Map;
1016

11-
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.*;
1218

1319
public class BWEMTest {
1420
static class BWEMMap{
@@ -66,13 +72,38 @@ public int hashCode() {
6672
mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35));
6773
}
6874

75+
@Test
76+
public void chokePointsFromDifferentMapsAreDistinct() throws IOException {
77+
BWEM first = new BWEM(GameBuilder.createGame());
78+
first.initialize();
79+
BWEM second = new BWEM(GameBuilder.createGame());
80+
second.initialize();
81+
assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints()));
82+
}
83+
6984
@Test
7085
public void checkSSCAITMaps() throws IOException {
7186
for (String mapName : mapData.keySet()) {
72-
Game game = GameBuilder.createGame(mapName);
73-
BWEM bwem = new BWEM(game);
74-
bwem.initialize();
75-
assertEquals(new BWEMMap(bwem.getMap()), mapData.get(mapName));
87+
BWTA.readMap(GameBuilder.createGame(mapName));
88+
BWTA.analyze();
89+
BWMap map = BWTA.getBWEM().getMap();
90+
assertEquals(new BWEMMap(map), mapData.get(mapName));
91+
assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size());
92+
93+
List<Chokepoint> chokes = BWTA.getChokepoints();
94+
assertEquals(mapName, map.getChokePoints().size(), chokes.size());
95+
for (Chokepoint choke : chokes) {
96+
assertTrue(choke.getRegions().getLeft().getChokepoints().contains(choke));
97+
assertTrue(choke.getRegions().getRight().getChokepoints().contains(choke));
98+
}
99+
for (Region region : BWTA.getRegions()) {
100+
for (Chokepoint choke : region.getChokepoints()) {
101+
assertNotNull(mapName, choke);
102+
assertTrue(mapName, chokes.contains(choke));
103+
assertTrue(choke.getRegions().getLeft().equals(region)
104+
|| choke.getRegions().getRight().equals(region));
105+
}
106+
}
76107
}
77108
}
78109
}

0 commit comments

Comments
 (0)