Skip to content

Commit fccda05

Browse files
committed
fix isParticipating/observer related bug(s)
1 parent f7dafc2 commit fccda05

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Build Status](https://travis-ci.org/JavaBWAPI/JBWAPI.svg?branch=develop)](https://travis-ci.org/JavaBWAPI/JBWAPI)[![Total alerts](https://img.shields.io/lgtm/alerts/g/JavaBWAPI/JBWAPI.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JavaBWAPI/JBWAPI/alerts/)[![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/JavaBWAPI/JBWAPI.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/JavaBWAPI/JBWAPI/context:java)
22
# JBWAPI
3-
Pure Java [bwapi](https://github.com/bwapi/bwapi) client (4.2.0 & 4.4.0) implementation backed by [N00byEdge](https://github.com/N00byEdge)'s [JavaBWAPIBackend](https://github.com/N00byEdge/JavaBWAPIBackend) idea and automated by [Bytekeeper](https://github.com/Bytekeeper).
3+
Pure Java [bwapi](https://github.com/bwapi/bwapi) 4.4.0 client implementation backed by [N00byEdge](https://github.com/N00byEdge)'s [JavaBWAPIBackend](https://github.com/N00byEdge/JavaBWAPIBackend) idea and automated by [Bytekeeper](https://github.com/Bytekeeper).
44

55
Also contains the pure Java BWEM implementation from [BWAPI4J](https://github.com/OpenBW/BWAPI4J).
66

@@ -36,7 +36,7 @@ Add JBWAPI as a dependecy
3636
<dependency>
3737
<groupId>com.github.JavaBWAPI</groupId>
3838
<artifactId>JBWAPI</artifactId>
39-
<version>0.6</version>
39+
<version>0.7</version>
4040
</dependency>
4141
```
4242

@@ -54,7 +54,7 @@ allprojects {
5454
Add JBWAPI as a dependecy
5555
```
5656
dependencies {
57-
implementation 'com.github.JavaBWAPI:JBWAPI:0.6'
57+
implementation 'com.github.JavaBWAPI:JBWAPI:0.7'
5858
}
5959
```
6060

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>jbwapi</groupId>
88
<artifactId>jbwapi</artifactId>
9-
<version>0.6</version>
9+
<version>0.7</version>
1010

1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/bwapi/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Client {
4444
+ 4 // IsConnected
4545
+ 4 // LastKeepAliveTime
4646
;
47-
private static final List<Integer> SUPPORTED_BWAPI_VERSIONS = Arrays.asList(10002, 10003);
47+
private static final List<Integer> SUPPORTED_BWAPI_VERSIONS = Arrays.asList(10003);
4848
private static final int MAX_COUNT = 19999;
4949

5050
private static final int maxNumGames = 8;

src/main/java/bwapi/Game.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public class Game {
5656
private List<Force> forceSet;
5757
private List<Player> playerSet;
5858
private List<Region> regionSet;
59+
60+
private List<Player> allies;
61+
private List<Player> enemies;
62+
private List<Player> observers;
63+
5964
// CHANGING
6065
private Unit[] units;
6166

@@ -189,6 +194,8 @@ void init() {
189194
this.staticNeutralUnits = Collections.unmodifiableList(staticNeutralUnits);
190195
this.allUnits = Collections.unmodifiableList(allUnits);
191196

197+
198+
192199
randomSeed = gameData.getRandomSeed();
193200

194201
revision = gameData.getRevision();
@@ -237,6 +244,15 @@ void init() {
237244

238245
mapPixelWidth = mapWidth * TilePosition.SIZE_IN_PIXELS;
239246
mapPixelHeight = mapHeight * TilePosition.SIZE_IN_PIXELS;
247+
248+
249+
enemies = playerSet.stream().filter(p -> !p.equals(self) && self.isEnemy(p))
250+
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
251+
allies = playerSet.stream().filter(p -> !p.equals(self) && self.isAlly(p))
252+
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
253+
254+
observers = playerSet.stream().filter(p -> !p.equals(self) && p.isObserver())
255+
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
240256
}
241257

242258
void unitCreate(final int id) {
@@ -1088,25 +1104,15 @@ public Player neutral() {
10881104
}
10891105

10901106
public List<Player> allies() {
1091-
final Player self = self();
1092-
return getPlayers().stream()
1093-
.filter(self::isAlly)
1094-
.collect(Collectors.toList());
1107+
return allies;
10951108
}
10961109

1097-
//TODO FIX in 4.3.0
10981110
public List<Player> enemies() {
1099-
final Player self = self();
1100-
return getPlayers().stream()
1101-
.filter(p -> !(p.isNeutral() || self.isAlly(p)))
1102-
.collect(Collectors.toList());
1111+
return enemies;
11031112
}
11041113

1105-
//TODO FIX in 4.3.0
11061114
public List<Player> observers() {
1107-
return getPlayers().stream()
1108-
.filter(Player::isObserver)
1109-
.collect(Collectors.toList());
1115+
return observers;
11101116
}
11111117

11121118
public void drawText(final CoordinateType ctype, final int x, final int y, final String cstr_format) {

src/main/java/bwapi/Player.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ public Force getForce() {
5757
}
5858

5959
public boolean isAlly(final Player player) {
60+
if (player == null || isNeutral() || player.isNeutral() || isObserver() || player.isObserver()) {
61+
return false;
62+
}
6063
return playerData.isAlly(player.getID());
6164
}
6265

63-
//TODO FIX OBSERVERS in 4.3.0
6466
public boolean isEnemy(final Player player) {
65-
if (player.isNeutral()) {
67+
if (player == null || isNeutral() || player.isNeutral() || isObserver() || player.isObserver()) {
6668
return false;
6769
}
68-
return !isAlly(player);
70+
return !playerData.isAlly(player.getID());
6971
}
7072

7173
public boolean isNeutral() {

0 commit comments

Comments
 (0)