33import battlecode .instrumenter .SandboxedRobotPlayer ;
44import battlecode .instrumenter .profiler .Profiler ;
55import battlecode .server .ErrorReporter ;
6+ import battlecode .world .control .PlayerControlProvider ;
67
78import java .io .PrintStream ;
89import java .lang .Math ;
@@ -33,6 +34,7 @@ public final class RobotMonitor {
3334 private static SandboxedRobotPlayer .Killer killer ;
3435
3536 private static Profiler profiler ;
37+ private static PlayerControlProvider provider ;
3638
3739 // Methods called from SandboxedRobotPlayer
3840
@@ -46,12 +48,14 @@ public final class RobotMonitor {
4648 * @param theKiller killer to use to kill the thread
4749 * @param seed seed to use for new Random instances
4850 * @param theProfiler profiler to log bytecode usage per method to (profiling is disabled if null)
51+ * @param theProvider player control provider to query computation time remaining
4952 */
5053 @ SuppressWarnings ("unused" )
5154 public static void init (SandboxedRobotPlayer .Pauser thePauser ,
5255 SandboxedRobotPlayer .Killer theKiller ,
5356 int seed ,
54- Profiler theProfiler ) {
57+ Profiler theProfiler ,
58+ PlayerControlProvider theProvider ) {
5559 shouldDie = false ;
5660 bytecodesLeft = 0 ;
5761 debugLevel = 0 ;
@@ -61,6 +65,7 @@ public static void init(SandboxedRobotPlayer.Pauser thePauser,
6165 killer = theKiller ;
6266
6367 profiler = theProfiler ;
68+ provider = theProvider ;
6469 }
6570
6671 /**
@@ -111,6 +116,23 @@ public static int getBytecodesLeft() {
111116 return bytecodesLeft ;
112117 }
113118
119+ /**
120+ * @return the bytecode number that the active robot is currently on.
121+ * Note that this can be above bytecodeLimit in some cases.
122+ */
123+ @ SuppressWarnings ("unused" )
124+ public static long getTimeElapsed () {
125+ return provider .getTimeElapsed ();
126+ }
127+
128+ /**
129+ * @return the bytecodes this robot has left to use.
130+ */
131+ @ SuppressWarnings ("unused" )
132+ public static long getTimeLeft () {
133+ return provider .getTimeLeft ();
134+ }
135+
114136 // Methods called from RobotPlayer
115137
116138 /**
0 commit comments