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
18 changes: 4 additions & 14 deletions src/main/java/bwem/ChokePoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class ChokePoint {
private final Graph graph;
private final boolean isPseudo;
private final int index;
private final String mapHash;
private final Pair<Area, Area> areas;
private final WalkPosition[] nodes;
private final List<Pair<WalkPosition, WalkPosition>> nodesInArea;
Expand All @@ -64,6 +65,7 @@ public final class ChokePoint {

this.graph = graph;
this.index = index;
this.mapHash = graph.getMap().game.mapHash();
this.areas = new Pair<>(area1, area2);
this.geometry = geometry;

Expand Down Expand Up @@ -313,25 +315,13 @@ 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. */
return this.index == that.index && Objects.equals(this.mapHash, that.mapHash);
}
}

@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(this.index, this.mapHash);
}

/**
Expand Down
38 changes: 37 additions & 1 deletion src/test/java/bwapi/BWEMTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package bwapi;

import bwem.Area;
import bwem.BWEM;
import bwem.BWMap;
import bwem.ChokePoint;
import org.junit.Test;

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

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

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

@Test
public void chokePointsFromSameMapAreEqual() throws IOException {
BWEM first = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
first.initialize();
BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
second.initialize();
assertEquals(first.getMap().getChokePoints(), second.getMap().getChokePoints());
assertEquals(new HashSet<>(first.getMap().getChokePoints()), new HashSet<>(second.getMap().getChokePoints()));
}

@Test
public void chokePointsFromDifferentMapsAreDistinct() throws IOException {
Comment thread
JasperGeurtz marked this conversation as resolved.
Resolved
BWEM first = new BWEM(GameBuilder.createGame("(2)Benzene.scx"));
first.initialize();
BWEM second = new BWEM(GameBuilder.createGame("(2)Destination.scx"));
second.initialize();
assertTrue(Collections.disjoint(first.getMap().getChokePoints(), second.getMap().getChokePoints()));
}

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

for (Area area : map.getAreas()) {
for (ChokePoint firstChokePoint : area.getChokePoints()) {
for (ChokePoint secondChokePoint : area.getChokePoints()) {
if (!firstChokePoint.isBlocked() && !secondChokePoint.isBlocked()) {
assertTrue(mapName, firstChokePoint.accessibleFrom(secondChokePoint));
}
}
}
}
}
}
}
Loading