Skip to content

Commit 88a901f

Browse files
authored
Merge pull request #130 from battlecode/release-1.3.1
Fixed headquarter color bug and islands on edge issue
2 parents 85017b6 + 3aadb3f commit 88a901f

7 files changed

Lines changed: 30 additions & 41 deletions

File tree

client/visualizer/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export enum Mode {
154154
export function defaults(supplied?: any): Config {
155155
let year = "2023"
156156
let conf: Config = {
157-
gameVersion: "1.3.0", //TODO: Change this on each release!
157+
gameVersion: "1.3.1", //TODO: Change this on each release!
158158
year: year,
159159
map_extension: 'map'+year.substring(2),
160160
game_extension: 'bc'+year.substring(2),

engine/src/main/battlecode/common/GameConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class GameConstants {
1010
/**
1111
* The current spec version the server compiles with.
1212
*/
13-
public static final String SPEC_VERSION = "1.3.0";
13+
public static final String SPEC_VERSION = "1.3.1";
1414

1515
// *********************************
1616
// ****** MAP CONSTANTS ************

engine/src/main/battlecode/server/Server.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ private void extendOut(LiveMap liveMap, MapLocation mapLocation, Set<MapLocation
234234
for (Direction dir : Direction.cardinalDirections()) {
235235
MapLocation newLocation = mapLocation.add(dir);
236236
if (seenLocations.contains(newLocation)) {continue;}
237+
if (!onTheMap(liveMap, newLocation)) {continue;}
237238
if (islandArray[locationToIndex(liveMap, newLocation)] == currValue) {
238239
extendOut(liveMap, newLocation, seenLocations);
239240
}
@@ -452,14 +453,14 @@ private Team runMatch(GameInfo currentGame,
452453
final LiveMap loadedMap;
453454

454455
try {
455-
loadedMap = GameMapIO.loadMap(mapName, new File(options.get("bc.game.map-path")));
456+
loadedMap = GameMapIO.loadMap(mapName, new File(options.get("bc.game.map-path")), teamsReversed);
456457
} catch (IOException e) {
457458
warn("Couldn't load map " + mapName + ", skipping");
458459
throw e;
459460
}
460461

461462
// Create the game world!
462-
currentWorld = new GameWorld(loadedMap, prov, gameMaker.getMatchMaker(), teamsReversed);
463+
currentWorld = new GameWorld(loadedMap, prov, gameMaker.getMatchMaker());
463464

464465
if (checkMapGuarantees) {
465466
// Validate the map

engine/src/main/battlecode/world/GameMapIO.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ public final strictfp class GameMapIO {
4848
* @return LiveMap for map
4949
* @throws IOException if the map fails to load or can't be found.
5050
*/
51-
public static LiveMap loadMap(String mapName, File mapDir) throws IOException {
51+
public static LiveMap loadMap(String mapName, File mapDir, boolean teamsReversed) throws IOException {
5252
final LiveMap result;
5353

5454
final File mapFile = new File(mapDir, mapName + MAP_EXTENSION);
5555
if (mapFile.exists()) {
56-
result = loadMap(new FileInputStream(mapFile));
56+
result = loadMap(new FileInputStream(mapFile), teamsReversed);
5757
} else {
5858
final InputStream backupStream = BACKUP_LOADER.getResourceAsStream(DEFAULT_MAP_PACKAGE + mapName + MAP_EXTENSION);
5959
if (backupStream == null) {
6060
throw new IOException("Can't load map: " + mapName + " from dir " + mapDir + " or default maps.");
6161
}
62-
result = loadMap(backupStream);
62+
result = loadMap(backupStream, teamsReversed);
6363
}
6464

6565
if (!result.getMapName().equals(mapName)) {
@@ -73,7 +73,7 @@ public static LiveMap loadMap(String mapName, File mapDir) throws IOException {
7373

7474
public static LiveMap loadMapAsResource(final ClassLoader loader,
7575
final String mapPackage,
76-
final String map) throws IOException {
76+
final String map, final boolean teamsReversed) throws IOException {
7777
final InputStream mapStream = loader.getResourceAsStream(
7878
mapPackage + (mapPackage.endsWith("/")? "" : "/") +
7979
map + MAP_EXTENSION
@@ -83,7 +83,7 @@ public static LiveMap loadMapAsResource(final ClassLoader loader,
8383
throw new IOException("Can't load map: " + map + " from package " + mapPackage);
8484
}
8585

86-
final LiveMap result = loadMap(mapStream);
86+
final LiveMap result = loadMap(mapStream, teamsReversed);
8787

8888
if (!result.getMapName().equals(map)) {
8989
throw new IOException("Invalid map: name (" + result.getMapName()
@@ -101,8 +101,8 @@ public static LiveMap loadMapAsResource(final ClassLoader loader,
101101
* @return a map read from the stream
102102
* @throws IOException if the read fails somehow
103103
*/
104-
public static LiveMap loadMap(InputStream stream) throws IOException {
105-
return Serial.deserialize(IOUtils.toByteArray(stream));
104+
public static LiveMap loadMap(InputStream stream, boolean teamsReversed) throws IOException {
105+
return Serial.deserialize(IOUtils.toByteArray(stream), teamsReversed);
106106
}
107107

108108
/**
@@ -189,12 +189,12 @@ public static class Serial {
189189
* @param mapBytes the raw bytes of the map
190190
* @return a new copy of the map as a LiveMap
191191
*/
192-
public static LiveMap deserialize(byte[] mapBytes) {
192+
public static LiveMap deserialize(byte[] mapBytes, boolean teamsReversed) {
193193
battlecode.schema.GameMap rawMap = battlecode.schema.GameMap.getRootAsGameMap(
194194
ByteBuffer.wrap(mapBytes)
195195
);
196196

197-
return Serial.deserialize(rawMap);
197+
return Serial.deserialize(rawMap, teamsReversed);
198198
}
199199

200200
/**
@@ -219,7 +219,7 @@ public static byte[] serialize(LiveMap gameMap) {
219219
* @param raw the flatbuffer map pointer
220220
* @return a new copy of the map as a LiveMap
221221
*/
222-
public static LiveMap deserialize(battlecode.schema.GameMap raw) {
222+
public static LiveMap deserialize(battlecode.schema.GameMap raw, boolean teamsReversed) {
223223
final int width = (int) (raw.maxCorner().x() - raw.minCorner().x());
224224
final int height = (int) (raw.maxCorner().y() - raw.minCorner().y());
225225
final MapLocation origin = new MapLocation((int) raw.minCorner().x(), (int) raw.minCorner().y());
@@ -243,7 +243,7 @@ public static LiveMap deserialize(battlecode.schema.GameMap raw) {
243243

244244
ArrayList<RobotInfo> initBodies = new ArrayList<>();
245245
SpawnedBodyTable bodyTable = raw.bodies();
246-
initInitialBodiesFromSchemaBodyTable(bodyTable, initBodies);
246+
initInitialBodiesFromSchemaBodyTable(bodyTable, initBodies, teamsReversed);
247247

248248
RobotInfo[] initialBodies = initBodies.toArray(new RobotInfo[initBodies.size()]);
249249

@@ -335,7 +335,7 @@ public static int serialize(FlatBufferBuilder builder, LiveMap gameMap) {
335335
// *** HELPER METHODS *********
336336
// ****************************
337337

338-
private static void initInitialBodiesFromSchemaBodyTable(SpawnedBodyTable bodyTable, ArrayList<RobotInfo> initialBodies) {
338+
private static void initInitialBodiesFromSchemaBodyTable(SpawnedBodyTable bodyTable, ArrayList<RobotInfo> initialBodies, boolean teamsReversed) {
339339
VecTable locs = bodyTable.locs();
340340
for (int i = 0; i < bodyTable.robotIDsLength(); i++) {
341341
// all initial bodies should be headquarters
@@ -344,11 +344,14 @@ private static void initInitialBodiesFromSchemaBodyTable(SpawnedBodyTable bodyTa
344344
int bodyX = locs.xs(i);
345345
int bodyY = locs.ys(i);
346346
Team bodyTeam = TeamMapping.team(bodyTable.teamIDs(i));
347+
if (teamsReversed) {
348+
bodyTeam = bodyTeam.opponent();
349+
}
347350
if (bodyType == RobotType.HEADQUARTERS) {
348351
Inventory headquarterInventory = new Inventory();
349352
initialBodies.add(new RobotInfo(bodyID, bodyTeam, bodyType, headquarterInventory, RobotType.HEADQUARTERS.health, new MapLocation(bodyX, bodyY)));
350353
}
351-
// ignore robots that are not archons, TODO throw error?
354+
// ignore robots that are not headquarters, TODO throw error?
352355
}
353356
}
354357
}

engine/src/main/battlecode/world/GameWorld.java

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,8 @@ public strictfp class GameWorld {
5252
private Random rand;
5353
private final GameMaker.MatchMaker matchMaker;
5454

55-
public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker matchMaker) {
56-
this(gm, cp, matchMaker, false);
57-
}
58-
5955
@SuppressWarnings("unchecked")
60-
public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker matchMaker, boolean reverseTeams) {
56+
public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker matchMaker) {
6157
this.walls = gm.getWallArray();
6258
this.clouds = gm.getCloudArray();
6359
this.islandIds = gm.getIslandArray();
@@ -86,26 +82,9 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match
8682

8783
// Add the robots contained in the LiveMap to this world.
8884
RobotInfo[] initialBodies = this.gameMap.getInitialBodies();
89-
RobotInfo[] bodiesToUse = initialBodies;
90-
RobotInfo[] reversedBodies = new RobotInfo[initialBodies.length];
85+
9186
for (int i = 0; i < initialBodies.length; i++) {
9287
RobotInfo robot = initialBodies[i];
93-
Inventory inv = new Inventory();
94-
for (ResourceType rType : ResourceType.values()) {
95-
if (rType == ResourceType.NO_RESOURCE) {
96-
continue;
97-
}
98-
inv.addResource(rType, robot.getResourceAmount(rType));
99-
}
100-
reversedBodies[i] = new RobotInfo(robot.ID, robot.team.opponent(), robot.type, inv, robot.health, robot.location);
101-
}
102-
103-
if (reverseTeams) {
104-
bodiesToUse = reversedBodies;
105-
}
106-
107-
for (int i = 0; i < bodiesToUse.length; i++) {
108-
RobotInfo robot = bodiesToUse[i];
10988
MapLocation newLocation = robot.location.translate(gm.getOrigin().x, gm.getOrigin().y);
11089
spawnRobot(robot.ID, robot.type, newLocation, robot.team);
11190
}

engine/src/test/battlecode/world/GenerateMaps.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ public void makeSimple() throws IOException {
3939
)
4040
)
4141
.build();
42+
boolean teamsReversed = false;
4243
GameMapIO.writeMap(map, new File("/Users/ezou/dev/battlecode20/engine/src/main/battlecode/world/maptest"));
43-
LiveMap test = GameMapIO.loadMap("maptest", new File("/Users/ezou/dev/battlecode20/engine/src/main/battlecode/world/resources"));
44+
LiveMap test = GameMapIO.loadMap("maptest", new File("/Users/ezou/dev/battlecode20/engine/src/main/battlecode/world/resources"), teamsReversed);
4445
// System.out.println(test.toString());
4546
}
4647
}

specs/specs.md.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@
287287

288288
# Appendix: Changelog
289289

290+
- Version 1.3.1 (January 15, 2023)
291+
- Engine Fixes:
292+
- Fixed headquarter colors being reversed when teams are reversed (from alternateOrder)
293+
- Fixed issue in checking maps with islands on edges
294+
290295
- Version 1.3.0 (January 15, 2023)
291296
- Spec Fixes:
292297
- Clarified that clouds change vision radius to 4 units

0 commit comments

Comments
 (0)