File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
engine/src/main/battlecode Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -85,8 +85,16 @@ public class GameConstants {
8585 /** The percent of the map which a team needs to paint to win. */
8686 public static final int PAINT_PERCENT_TO_WIN = 70 ;
8787
88- /** The maximum number of towers that a team can have. */
89- public static final int MAX_NUMBER_OF_TOWERS = 25 ;
88+ /** The maximum number of towers that a team can have. */
89+ public static final int MAX_NUMBER_OF_TOWERS = 25 ;
90+
91+ /**
92+ * The maximum execution time that can be spent on a team in one match. If the total time spent executing a team's bots
93+ * exceeds this limit, the team will immediately lose the game. Execution time is measured in ns.
94+ */
95+ // public static final long MAX_TEAM_EXECUTION_TIME = 1200000000000L;
96+
97+ public static final long MAX_TEAM_EXECUTION_TIME = 5000000000L ;
9098
9199 // *********************************
92100 // ****** GAME MECHANICS ***********
Original file line number Diff line number Diff line change 11package battlecode .world .control ;
22
3+ import battlecode .common .GameConstants ;
34import battlecode .common .Team ;
45import battlecode .instrumenter .InstrumentationException ;
56import battlecode .instrumenter .TeamClassLoaderFactory ;
@@ -70,6 +71,11 @@ public class PlayerControlProvider implements RobotControlProvider {
7071 */
7172 private int matchId = -1 ;
7273
74+ /**
75+ * The total time the player's bots have spent executing, measured in ns
76+ */
77+ private long totalPlayerTime = 0 ;
78+
7379 /**
7480 * Create a new PlayerControlProvider.
7581 *
@@ -116,6 +122,7 @@ public void matchEnded() {
116122
117123 this .sandboxes .clear ();
118124 this .gameWorld = null ;
125+ this .totalPlayerTime = 0 ;
119126 }
120127
121128 @ Override
@@ -173,7 +180,12 @@ public void runRobot(InternalRobot robot) {
173180
174181 if (player != null ) {
175182 player .setBytecodeLimit (robot .getBytecodeLimit ());
183+ long timeBefore = System .nanoTime ();
176184 player .step ();
185+ totalPlayerTime += (System .nanoTime () - timeBefore );
186+ if (totalPlayerTime > GameConstants .MAX_TEAM_EXECUTION_TIME ) {
187+ robot .getController ().resign ();
188+ }
177189 }
178190 }
179191
You can’t perform that action at this time.
0 commit comments