Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/main/java/bwapi/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ final public boolean hasPower(final int tileX, final int tileY, final UnitType u
if (unitType.id >= 0 && unitType.id < UnitType.None.id) {
return hasPowerPrecise(tileX * 32 + unitType.tileWidth() * 16, tileY * 32 + unitType.tileHeight() * 16, unitType);
}
return hasPowerPrecise(tileY * 32, tileY * 32, UnitType.None);
return hasPowerPrecise(tileX * 32, tileY * 32, UnitType.None);
}

final public boolean hasPower(final int tileX, final int tileY, final int tileWidth, final int tileHeight) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/bwapi/GameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,19 @@ public void ifReplaySelfAndEnemyShouldBeNull() throws IOException {
assertTrue(game.enemies().isEmpty());
assertTrue(game.allies().isEmpty());
}

@Test
public void hasPowerOnTile() throws IOException {
Game game = GameBuilder.createGame();
Unit pylon = mock(Unit.class);
given(pylon.getType()).willReturn(UnitType.Protoss_Pylon);
given(pylon.getPlayer()).willReturn(game.self());
given(pylon.exists()).willReturn(true);
given(pylon.isCompleted()).willReturn(true);
given(pylon.getPosition()).willReturn(new Position(1024, 512));
game.setAllUnits(Collections.singletonList(pylon));

// tile (31, 15) is pixel (992, 480), right next to the pylon
assertTrue(game.hasPower(31, 15));
}
}
Loading