Skip to content

Commit

Permalink
update mopping + metadata schema, fix mark actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Gonzalez Hermosillo committed Jan 3, 2025
1 parent f6fd651 commit 024c428
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 49 deletions.
7 changes: 2 additions & 5 deletions engine/src/main/battlecode/common/GameConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ public class GameConstants {
/** The number of defense towers a player starts with */
public static final int NUMBER_INITIAL_DEFENSE_TOWERS = 0;

/** The amount of a paint a paint tower starts with. */
public static final int INITIAL_PAINT_TOWER_PAINT = 500;

/** The percentage of a robot's paint capacity that is full when first built. */
public static final int INITIAL_ROBOT_PAINT_PERCENTAGE = 50;
/** The percentage of a unit's paint capacity that is full when first built. */
public static final int INITIAL_UNIT_PAINT_PERCENTAGE = 50;

/** The width and height of the patterns that robots can draw */
public static final int PATTERN_SIZE = 5;
Expand Down
19 changes: 13 additions & 6 deletions engine/src/main/battlecode/schema/MopAction.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// automatically generated by the FlatBuffers compiler, do not modify

package battlecode.schema;
Expand Down Expand Up @@ -27,11 +28,18 @@ public final class MopAction extends Struct {
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
public MopAction __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }

public int loc() { return bb.getShort(bb_pos + 0) & 0xFFFF; }

public static int createMopAction(FlatBufferBuilder builder, int loc) {
builder.prep(2, 2);
builder.putShort((short) loc);
/**
* Ids of the mopped targets, possibly 0
*/
public int id0() { return bb.getShort(bb_pos + 0) & 0xFFFF; }
public int id1() { return bb.getShort(bb_pos + 2) & 0xFFFF; }
public int id2() { return bb.getShort(bb_pos + 4) & 0xFFFF; }

public static int createMopAction(FlatBufferBuilder builder, int id0, int id1, int id2) {
builder.prep(2, 6);
builder.putShort((short) id2);
builder.putShort((short) id1);
builder.putShort((short) id0);
return builder.offset();
}

Expand All @@ -42,4 +50,3 @@ public static final class Vector extends BaseVector {
public MopAction get(MopAction obj, int j) { return obj.__assign(__element(j), bb); }
}
}

27 changes: 17 additions & 10 deletions engine/src/main/battlecode/schema/RobotTypeMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,45 @@ public final class RobotTypeMetadata extends Table {
public int actionCooldown() { int o = __offset(6); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int movementCooldown() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int baseHealth() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int actionRadiusSquared() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int visionRadiusSquared() { int o = __offset(14); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int bytecodeLimit() { int o = __offset(16); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int basePaint() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int maxPaint() { int o = __offset(14); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int actionRadiusSquared() { int o = __offset(16); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int visionRadiusSquared() { int o = __offset(18); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
public int bytecodeLimit() { int o = __offset(20); return o != 0 ? bb.getInt(o + bb_pos) : 0; }

public static int createRobotTypeMetadata(FlatBufferBuilder builder,
byte type,
int actionCooldown,
int movementCooldown,
int baseHealth,
int basePaint,
int maxPaint,
int actionRadiusSquared,
int visionRadiusSquared,
int bytecodeLimit) {
builder.startTable(7);
builder.startTable(9);
RobotTypeMetadata.addBytecodeLimit(builder, bytecodeLimit);
RobotTypeMetadata.addVisionRadiusSquared(builder, visionRadiusSquared);
RobotTypeMetadata.addActionRadiusSquared(builder, actionRadiusSquared);
RobotTypeMetadata.addMaxPaint(builder, maxPaint);
RobotTypeMetadata.addBasePaint(builder, basePaint);
RobotTypeMetadata.addBaseHealth(builder, baseHealth);
RobotTypeMetadata.addMovementCooldown(builder, movementCooldown);
RobotTypeMetadata.addActionCooldown(builder, actionCooldown);
RobotTypeMetadata.addType(builder, type);
return RobotTypeMetadata.endRobotTypeMetadata(builder);
}

public static void startRobotTypeMetadata(FlatBufferBuilder builder) { builder.startTable(7); }
public static void startRobotTypeMetadata(FlatBufferBuilder builder) { builder.startTable(9); }
public static void addType(FlatBufferBuilder builder, byte type) { builder.addByte(0, type, 0); }
public static void addActionCooldown(FlatBufferBuilder builder, int actionCooldown) { builder.addInt(1, actionCooldown, 0); }
public static void addMovementCooldown(FlatBufferBuilder builder, int movementCooldown) { builder.addInt(2, movementCooldown, 0); }
public static void addBaseHealth(FlatBufferBuilder builder, int baseHealth) { builder.addInt(3, baseHealth, 0); }
public static void addActionRadiusSquared(FlatBufferBuilder builder, int actionRadiusSquared) { builder.addInt(4, actionRadiusSquared, 0); }
public static void addVisionRadiusSquared(FlatBufferBuilder builder, int visionRadiusSquared) { builder.addInt(5, visionRadiusSquared, 0); }
public static void addBytecodeLimit(FlatBufferBuilder builder, int bytecodeLimit) { builder.addInt(6, bytecodeLimit, 0); }
public static void addBasePaint(FlatBufferBuilder builder, int basePaint) { builder.addInt(4, basePaint, 0); }
public static void addMaxPaint(FlatBufferBuilder builder, int maxPaint) { builder.addInt(5, maxPaint, 0); }
public static void addActionRadiusSquared(FlatBufferBuilder builder, int actionRadiusSquared) { builder.addInt(6, actionRadiusSquared, 0); }
public static void addVisionRadiusSquared(FlatBufferBuilder builder, int visionRadiusSquared) { builder.addInt(7, visionRadiusSquared, 0); }
public static void addBytecodeLimit(FlatBufferBuilder builder, int bytecodeLimit) { builder.addInt(8, bytecodeLimit, 0); }
public static int endRobotTypeMetadata(FlatBufferBuilder builder) {
int o = builder.endTable();
return o;
Expand All @@ -73,5 +81,4 @@ public static final class Vector extends BaseVector {
public RobotTypeMetadata get(int j) { return get(new RobotTypeMetadata(), j); }
public RobotTypeMetadata get(RobotTypeMetadata obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
}
}

}
6 changes: 4 additions & 2 deletions engine/src/main/battlecode/server/GameMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ public int makeRobotTypeMetadata(FlatBufferBuilder builder){
}
RobotTypeMetadata.startRobotTypeMetadata(builder);
RobotTypeMetadata.addType(builder, FlatHelpers.getRobotTypeFromUnitType(type));
RobotTypeMetadata.addMaxPaint(builder, type.paintCapacity);
RobotTypeMetadata.addBasePaint(builder, (int) Math.round(type.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0));
RobotTypeMetadata.addActionCooldown(builder, type.actionCooldown);
RobotTypeMetadata.addActionRadiusSquared(builder, type.actionRadiusSquared);
RobotTypeMetadata.addBaseHealth(builder,type.health);
Expand Down Expand Up @@ -543,9 +545,9 @@ public void addAttackAction(int otherID){
}

/// Visually indicate a mop attack
public void addMopAction(MapLocation loc){
public void addMopAction(int id1, int id2, int id3){
applyToBuilders((builder) -> {
int action = MopAction.createMopAction(builder, locationToInt(loc));
int action = MopAction.createMopAction(builder, id1, id2, id3);
builder.addAction(action, Action.MopAction);
});
}
Expand Down
14 changes: 1 addition & 13 deletions engine/src/main/battlecode/world/GameMapIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,11 @@ private static void initInitialBodiesFromSchemaBodyTable(InitialBodyTable bodyTa
if (teamsReversed){
bodyTeam = bodyTeam.opponent();
}
int initialPaint = (bodyType == UnitType.LEVEL_ONE_PAINT_TOWER) ? GameConstants.INITIAL_PAINT_TOWER_PAINT : 0;
int initialPaint = (int) Math.round(bodyType.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0);
initialBodies.add(new RobotInfo(curId, bodyTeam, bodyType, bodyType.health, new MapLocation(bodyX, bodyY), initialPaint));
}
}

// private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList<Integer> ids, ArrayList<Integer> xs, ArrayList<Integer> ys, ArrayList<Byte> teams, ArrayList<Byte> types){
// ByteBuffer bb = builder.createUnintializedVector(6, xs.size(), 2);
// for (int i = 0; i < xs.size(); i++){
// bb.putInt(ids.get(i));
// bb.putShort((short)(int)xs.get(i));
// bb.putShort((short)(int)ys.get(i));
// bb.put(teams.get(i));
// bb.put(types.get(i));
// }
// return builder.endVector();
// }

private static int createSpawnActionsVector(FlatBufferBuilder builder, ArrayList<Integer> ids, ArrayList<Integer> xs, ArrayList<Integer> ys, ArrayList<Byte> teams, ArrayList<Byte> types){
InitialBodyTable.startSpawnActionsVector(builder, ids.size());
for (int i = 0; i < ids.size(); i++){
Expand Down
11 changes: 7 additions & 4 deletions engine/src/main/battlecode/world/GameWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ public int getMarker(Team team, MapLocation loc) {
}

public void setMarker(Team team, MapLocation loc, int marker) {
if (marker == 0){
this.matchMaker.addUnmarkAction(loc);
}
else {
this.matchMaker.addMarkAction(loc, !isPrimaryPaint(marker));
}
this.getmarkersArray(team)[locationToIndex(loc)] = marker;
}

Expand Down Expand Up @@ -947,10 +953,7 @@ public int spawnRobot(int ID, UnitType type, MapLocation location, Team team){
if (type.isTowerType()){
this.teamInfo.addTowers(1, team);
}
if (type == UnitType.LEVEL_ONE_PAINT_TOWER)
robot.addPaint(GameConstants.INITIAL_PAINT_TOWER_PAINT);
else if (type.isRobotType())
robot.addPaint((int) Math.round(type.paintCapacity * GameConstants.INITIAL_ROBOT_PAINT_PERCENTAGE / 100.0));
robot.addPaint((int) Math.round(type.paintCapacity * GameConstants.INITIAL_UNIT_PAINT_PERCENTAGE / 100.0));
return ID;
}

Expand Down
7 changes: 4 additions & 3 deletions engine/src/main/battlecode/world/InternalRobot.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ public void mopSwing(Direction dir) { // NOTE: only works for moppers!
if(dir == Direction.SOUTH) dirIdx = 1;
else if(dir == Direction.EAST) dirIdx = 2;
else if(dir == Direction.WEST) dirIdx = 3;
ArrayList<Integer> affectedIDs = new ArrayList<>();

for(int i = 0; i < 3; i ++) { // check all three spots
int x = this.getLocation().x + dx[dirIdx][i], y = this.getLocation().y + dy[dirIdx][i];
Expand All @@ -480,12 +481,12 @@ public void mopSwing(Direction dir) { // NOTE: only works for moppers!
InternalRobot robot = this.gameWorld.getRobot(newLoc);
if(this.team != robot.getTeam()){
robot.addPaint(-GameConstants.MOPPER_SWING_PAINT_DEPLETION);
this.gameWorld.getMatchMaker().addAttackAction(robot.getID());
affectedIDs.add(robot.ID);
}
}
}
MapLocation centerLoc = this.location.add(dir);
this.gameWorld.getMatchMaker().addMopAction(centerLoc);
for (int i = 0; i < 3; i++) affectedIDs.add(0);
this.gameWorld.getMatchMaker().addMopAction(affectedIDs.get(0), affectedIDs.get(1), affectedIDs.get(2));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion engine/src/main/battlecode/world/MapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void addTower(int id, Team team, MapLocation loc) {
UnitType.LEVEL_ONE_PAINT_TOWER,
UnitType.LEVEL_ONE_PAINT_TOWER.health,
loc,
GameConstants.INITIAL_PAINT_TOWER_PAINT
500
));
}

Expand Down
4 changes: 0 additions & 4 deletions engine/src/main/battlecode/world/RobotControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,7 @@ public boolean canMark(MapLocation loc) {
@Override
public void mark(MapLocation loc, boolean secondary) throws GameActionException {
assertCanMark(loc);

this.gameWorld.setMarker(getTeam(), loc, secondary ? 2 : 1);
this.gameWorld.getMatchMaker().addMarkAction(loc, secondary);
}

private void assertCanRemoveMark(MapLocation loc) throws GameActionException {
Expand All @@ -560,9 +558,7 @@ public boolean canRemoveMark(MapLocation loc) {
@Override
public void removeMark(MapLocation loc) throws GameActionException {
assertCanRemoveMark(loc);

this.gameWorld.setMarker(getTeam(), loc, 0);
this.gameWorld.getMatchMaker().addUnmarkAction(loc);
}

private void assertCanMarkTowerPattern(MapLocation loc) throws GameActionException {
Expand Down
7 changes: 6 additions & 1 deletion schema/battlecode.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ table RobotTypeMetadata {
actionCooldown: int;
movementCooldown: int;
baseHealth: int;
basePaint: int;
maxPaint: int;
actionRadiusSquared: int;
visionRadiusSquared: int;
bytecodeLimit: int;
Expand Down Expand Up @@ -92,7 +94,10 @@ struct AttackAction {

/// Visually indicate a mop attack
struct MopAction {
loc: ushort;
/// Ids of the mopped targets, possibly 0
id0: ushort;
id1: ushort;
id2: ushort;
}

/// Visually indicate a tower being built
Expand Down

0 comments on commit 024c428

Please sign in to comment.