Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/main/java/bwem/ChokePoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,14 @@ public boolean equals(final Object object) {
return false;
} else {
final ChokePoint that = (ChokePoint) object;
final boolean lel = this.areas.getLeft().equals(that.areas.getLeft());
final boolean ler = this.areas.getLeft().equals(that.areas.getRight());
final boolean rer = this.areas.getRight().equals(that.areas.getRight());
final boolean rel = this.areas.getRight().equals(that.areas.getLeft());
return lel && rer
|| ler && rel; /* true if area pairs are an exact match or if one pair is reversed. */
// Parallel connections can share areas or even a center, but not a graph/index.
return this.graph == that.graph && this.index == that.index;
}
}

@Override
public int hashCode() {
int idLeft = areas.getLeft().getId().intValue();
int idRight = areas.getRight().getId().intValue();
if (idLeft > idRight) {
final int idLeftTmp = idLeft;
idLeft = idRight;
idRight = idLeftTmp;
}
return Objects.hash(idLeft, idRight);
return Objects.hash(graph, index);
}

/**
Expand Down
41 changes: 36 additions & 5 deletions src/test/java/bwapi/BWEMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import bwem.BWEM;
import bwem.BWMap;
import bwta.BWTA;
import bwta.Chokepoint;
import bwta.Region;
import org.junit.Test;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

public class BWEMTest {
static class BWEMMap{
Expand Down Expand Up @@ -66,13 +72,38 @@
mapData.put("(4)Roadrunner.scx", new BWEMMap(26, 12, 35));
}

@Test
public void chokePointsFromDifferentMapsAreDistinct() throws IOException {
BWEM first = new BWEM(GameBuilder.createGame());
first.initialize();
BWEM second = new BWEM(GameBuilder.createGame());
second.initialize();
assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints()));
}

@Test
public void checkSSCAITMaps() throws IOException {
for (String mapName : mapData.keySet()) {
Game game = GameBuilder.createGame(mapName);
BWEM bwem = new BWEM(game);
bwem.initialize();
assertEquals(new BWEMMap(bwem.getMap()), mapData.get(mapName));
BWTA.readMap(GameBuilder.createGame(mapName));
Comment thread
dgant marked this conversation as resolved.
Dismissed
BWTA.analyze();
BWMap map = BWTA.getBWEM().getMap();
assertEquals(new BWEMMap(map), mapData.get(mapName));
assertEquals(mapName, map.getChokePoints().size(), new HashSet<>(map.getChokePoints()).size());

List<Chokepoint> chokes = BWTA.getChokepoints();
assertEquals(mapName, map.getChokePoints().size(), chokes.size());
for (Chokepoint choke : chokes) {
assertTrue(choke.getRegions().getLeft().getChokepoints().contains(choke));
assertTrue(choke.getRegions().getRight().getChokepoints().contains(choke));
}
for (Region region : BWTA.getRegions()) {
for (Chokepoint choke : region.getChokepoints()) {
assertNotNull(mapName, choke);
assertTrue(mapName, chokes.contains(choke));
assertTrue(choke.getRegions().getLeft().equals(region)
|| choke.getRegions().getRight().equals(region));
}
}
}
}
}
Loading