Skip to content

Commit 7a0b705

Browse files
committed
add bwapi 4.4.0 support as there are no clientmapchanges
1 parent 239e9ab commit 7a0b705

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/main/java/bwapi/Client.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ of this software and associated documentation files (the "Software"), to deal
3535
import java.io.RandomAccessFile;
3636
import java.nio.ByteBuffer;
3737
import java.nio.ByteOrder;
38+
import java.util.Arrays;
39+
import java.util.List;
3840

3941
class Client {
4042
private static final int READ_WRITE = 0x1 | 0x2 | 0x4;
4143
private static final int GAME_SIZE = 4 // ServerProcID
4244
+ 4 // IsConnected
4345
+ 4 // LastKeepAliveTime
4446
;
45-
private static final int BWAPI_VERSION = 10002;
47+
private static final List<Integer> SUPPORTED_BWAPI_VERSIONS = Arrays.asList(10002, 10003);
48+
private static final int MAX_COUNT = 19999;
4649

4750
private static final int maxNumGames = 8;
4851
private static final int gameTableSize = GAME_SIZE * maxNumGames;
@@ -86,8 +89,8 @@ private void connect(final int procID) throws Exception {
8689
data = new ClientData(sharedMemory).new GameData(0);
8790

8891
final int clientVersion = data.getClient_version();
89-
if (clientVersion != BWAPI_VERSION) {
90-
throw new Exception("BWAPI version mismatch, expected: " + BWAPI_VERSION + ", got: " + clientVersion);
92+
if (!SUPPORTED_BWAPI_VERSIONS.contains(clientVersion)) {
93+
throw new Exception("BWAPI version mismatch, expected one of: " + SUPPORTED_BWAPI_VERSIONS + ", got: " + clientVersion);
9194
}
9295

9396
System.out.println("Connected to BWAPI@" + procID + " with version " + clientVersion + ": " + data.getRevision());
@@ -115,35 +118,35 @@ public interface EventHandler {
115118
}
116119

117120

118-
public String eventString(final int s) {
121+
String eventString(final int s) {
119122
return data.getEventStrings(s);
120123
}
121124

122-
public int addString(final String s) {
125+
int addString(final String s) {
123126
int stringCount = data.getStringCount();
124-
if (stringCount >= 19999) throw new IllegalStateException("Too many shapes!");
127+
if (stringCount >= MAX_COUNT) throw new IllegalStateException("Too many shapes!");
125128
data.setStringCount(stringCount + 1);
126129
data.setStrings(stringCount, s);
127130
return stringCount;
128131
}
129132

130-
public Shape addShape() {
133+
Shape addShape() {
131134
int shapeCount = data.getShapeCount();
132-
if (shapeCount >= 19999) throw new IllegalStateException("Too many shapes!");
135+
if (shapeCount >= MAX_COUNT) throw new IllegalStateException("Too many shapes!");
133136
data.setShapeCount(shapeCount + 1);
134137
return data.getShapes(shapeCount);
135138
}
136139

137-
public Command addCommand() {
140+
Command addCommand() {
138141
final int commandCount = data.getCommandCount();
139-
if (commandCount >= 19999) throw new IllegalStateException("Too many commands!");
142+
if (commandCount >= MAX_COUNT) throw new IllegalStateException("Too many commands!");
140143
data.setCommandCount(commandCount + 1);
141144
return data.getCommands(commandCount);
142145
}
143146

144-
public ClientData.UnitCommand addUnitCommand() {
147+
ClientData.UnitCommand addUnitCommand() {
145148
int unitCommandCount = data.getUnitCommandCount();
146-
if (unitCommandCount >= 19999) throw new IllegalStateException("Too many unit commands!");
149+
if (unitCommandCount >= MAX_COUNT) throw new IllegalStateException("Too many unit commands!");
147150
data.setUnitCommandCount(unitCommandCount + 1);
148151
return data.getUnitCommands(unitCommandCount);
149152
}

0 commit comments

Comments
 (0)