Skip to content

Commit 2fcd599

Browse files
committed
Identify chokepoints by map hash and index and test through BWEM
1 parent 1f1d242 commit 2fcd599

2 files changed

Lines changed: 31 additions & 25 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public final class ChokePoint {
4343
private final Graph graph;
4444
private final boolean isPseudo;
4545
private final int index;
46+
private final String mapHash;
4647
private final Pair<Area, Area> areas;
4748
private final WalkPosition[] nodes;
4849
private final List<Pair<WalkPosition, WalkPosition>> nodesInArea;
@@ -64,6 +65,7 @@ public final class ChokePoint {
6465

6566
this.graph = graph;
6667
this.index = index;
68+
this.mapHash = graph.getMap().game.mapHash();
6769
this.areas = new Pair<>(area1, area2);
6870
this.geometry = geometry;
6971

@@ -313,14 +315,13 @@ public boolean equals(final Object object) {
313315
return false;
314316
} else {
315317
final ChokePoint that = (ChokePoint) object;
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;
318+
return this.index == that.index && Objects.equals(this.mapHash, that.mapHash);
318319
}
319320
}
320321

321322
@Override
322323
public int hashCode() {
323-
return Objects.hash(graph, index);
324+
return Objects.hash(this.index, this.mapHash);
324325
}
325326

326327
/**

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

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package bwapi;
22

3+
import bwem.Area;
34
import bwem.BWEM;
45
import bwem.BWMap;
5-
import bwta.BWTA;
6-
import bwta.Chokepoint;
7-
import bwta.Region;
6+
import bwem.ChokePoint;
87
import org.junit.Test;
98

109
import java.io.IOException;
1110
import java.util.Collections;
1211
import java.util.HashMap;
1312
import java.util.HashSet;
14-
import java.util.List;
1513
import java.util.Map;
1614

17-
import static org.junit.Assert.*;
15+
import static org.junit.Assert.assertEquals;
16+
import static org.junit.Assert.assertTrue;
1817

1918
public class BWEMTest {
2019
static class BWEMMap{
@@ -72,36 +71,42 @@ public int hashCode() {
7271
mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35));
7372
}
7473

74+
@Test
75+
public void chokePointsFromSameMapAreEqual() throws IOException {
76+
BWEM first = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
77+
first.initialize();
78+
BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
79+
second.initialize();
80+
assertEquals(first.getMap().getChokePoints(), second.getMap().getChokePoints());
81+
assertEquals(new HashSet<>(first.getMap().getChokePoints()), new HashSet<>(second.getMap().getChokePoints()));
82+
}
83+
7584
@Test
7685
public void chokePointsFromDifferentMapsAreDistinct() throws IOException {
77-
BWEM first = new BWEM(GameBuilder.createGame());
86+
BWEM first = new BWEM(GameBuilder.createGame("(2)Benzene.scx"));
7887
first.initialize();
79-
BWEM second = new BWEM(GameBuilder.createGame());
88+
BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
8089
second.initialize();
8190
assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints()));
8291
}
8392

8493
@Test
8594
public void checkSSCAITMaps() throws IOException {
8695
for (String mapName : mapData.keySet()) {
87-
BWTA.readMap(GameBuilder.createGame(mapName));
88-
BWTA.analyze();
89-
BWMap map = BWTA.getBWEM().getMap();
96+
Game game = GameBuilder.createGame(mapName);
97+
BWEM bwem = new BWEM(game);
98+
bwem.initialize();
99+
BWMap map = bwem.getMap();
90100
assertEquals(new BWEMMap(map), mapData.get(mapName));
91101
assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size());
92102

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));
103+
for (Area area : map.getAreas()) {
104+
for (ChokePoint firstChokePoint : area.getChokePoints()) {
105+
for (ChokePoint secondChokePoint : area.getChokePoints()) {
106+
if (!firstChokePoint.isBlocked() && !secondChokePoint.isBlocked()) {
107+
assertTrue(mapName, firstChokePoint.accessibleFrom(secondChokePoint));
108+
}
109+
}
105110
}
106111
}
107112
}

0 commit comments

Comments
 (0)