protected void preloadRound() { logMessage("----------------------"); Logger.logMessage("Round " + (roundNum + 1) + " initializing..", false); }
protected void initializeRound() { logMessage(""); logMessage("Let the games begin!"); roundOver = false; endTimer = 0; currentTime = 0; }
public static void logWarning(String s) { logMessage("Warning: " + s, true); }
public static void logMessage(String s) { logMessage(s, true); }
private void cleanupRound() { logMessage("Round " + (roundNum + 1) + " cleaning up."); }
private void waitForStop(Thread thread) { for (int j = 0; j < 100 && thread.isAlive(); j++) { if (j == 50) { logMessage( "Waiting for robot " + robotProxy.getStatics().getName() + " to stop thread " + thread.getName()); } try { Thread.sleep(10); } catch (InterruptedException e) { // Immediately reasserts the exception by interrupting the caller thread itself Thread.currentThread().interrupt(); break; // We are in a loop } } }
private void setCpuConstant() { long count = 0; double d = 0; long start = System.currentTimeMillis(); while (System.currentTimeMillis() - start < TEST_PERIOD_MILLIS) { d += Math.hypot(Math.sqrt(Math.abs(log(Math.atan(Math.random())))), Math.cbrt(Math.abs(Math.random() * 10))) / exp(Math.random()); count++; } // to cheat optimizer, almost never happen if (d == 0.0) { Logger.logMessage("bingo!"); } cpuConstant = Math.max(1, (long) (1000000.0 * APPROXIMATE_CYCLES_ALLOWED * TEST_PERIOD_MILLIS / count)); }
private static void deleteFile(String filename) { Logger.logMessage("Deleting " + filename + "..."); try { recursivelyDelete(new File(filename)); } catch (IOException ex) { Logger.logError(ex.getMessage()); } }
private void setStatus(String message) { IWindowManager windowManager = Container.getComponent(IWindowManager.class); if (windowManager != null) { windowManager.setStatus(message); } if (message.length() > 0) { Logger.logMessage(message); } }
private static boolean loadModule(String module, ClassLoader loader) { try { if (known.contains(module)) { // Logger.logMessage("already loaded " + module); return false; } Class<?> modClass = loader.loadClass(module + ".Module"); final Object moduleInstance = modClass.newInstance(); if (moduleInstance instanceof IModule) { modules.add((IModule) moduleInstance); } Logger.logMessage("Loaded " + module); known.add(module); return true; } catch (ClassNotFoundException ignore) {// it is not our module ? // Logger.logMessage("Can't load " + module); } catch (IllegalAccessException e) { Logger.logError(e); } catch (InstantiationException e) { Logger.logError(e); } return false; }
public Properties getWindowPositions() { if (windowPositions == null) { windowPositions = new Properties(); FileInputStream in = null; try { in = new FileInputStream(FileUtil.getWindowConfigFile()); windowPositions.load(in); } catch (FileNotFoundException e) { Logger.logMessage("Creating " + FileUtil.getWindowConfigFile().getName() + " file"); } catch (Exception e) { Logger.logError(e); } finally { if (in != null) { try { in.close(); } catch (IOException ignored) {} } } } return windowPositions; }
private void replayBattle() { if (!recordManager.hasRecord()) { return; } logMessage("Preparing replay..."); if (battle != null && battle.isRunning()) { battle.stop(true); } Logger.setLogListener(battleEventDispatcher); recordManager.detachRecorder(); battle = Container.createComponent(BattlePlayer.class); Thread battleThread = new Thread(Thread.currentThread().getThreadGroup(), battle); battleThread.setPriority(Thread.NORM_PRIORITY); battleThread.setName("BattlePlayer Thread"); // Start the battlePlayer thread battleThread.start(); }
/** * @param t thread to stop * @return 0 as peaceful stop */ private int stopSteps(Thread t) { if (t != null && t.isAlive()) { interrupt(t); if (t.isAlive()) { stop(t); } if (t.isAlive()) { // noinspection deprecation // t.suspend(); logWarning("Unable to stop thread: " + runThread.getName()); } else { logMessage(robotProxy.getStatics().getName() + " has been stopped."); } return 1; } return 0; }
public static void clean() { File roborumbleTempFile = new File("roborumble/temp"); deleteFile(roborumbleTempFile.getPath()); deleteFile(FileUtil.getRobotsDataDir().getPath()); deleteFile(FileUtil.getRobotDatabaseFile().getPath()); FileUtil.createDir(roborumbleTempFile); final IRepositoryManager repositoryManager = Container.getComponent(IRepositoryManager.class); repositoryManager.reload(true); Logger.logMessage("Cleaning done."); }
public void waitSleeping(long millisWait, int nanosWait) { synchronized (isSleeping) { // It's quite possible for simple robots to // complete their processing before we get here, // so we test if the robot is already asleep. if (!isSleeping()) { try { for (long i = millisWait; i > 0 && !isSleeping() && isRunning(); i--) { isSleeping.wait(0, 999999); } if (!isSleeping() && isRunning()) { isSleeping.wait(0, nanosWait); } } catch (InterruptedException e) { // Immediately reasserts the exception by interrupting the caller thread itself Thread.currentThread().interrupt(); logMessage("Wait for " + getName() + " interrupted."); } } } }
public static EditorProperties getEditorProperties() { if (editorProperties == null) { editorProperties = new EditorProperties(); FileInputStream in = null; File file = null; try { in = new FileInputStream(FileUtil.getEditorConfigFile()); getEditorProperties().load(in); } catch (FileNotFoundException e) { logMessage("Editor properties file was not found. A new one will be created."); } catch (IOException e) { logError("Error while reading file: " + file, e); } finally { if (in != null) { try { in.close(); } catch (IOException ignored) {} } } } return editorProperties; }
public void calculateCpuConstant() { setStatus("Estimating CPU speed, please wait..."); setCpuConstant(); Logger.logMessage( "Each robot will be allowed a maximum of " + cpuConstant + " nanoseconds per turn on this system."); properties.setCpuConstant(cpuConstant); properties.saveProperties(); setStatus(""); }
public void startRound(long waitMillis, int waitNanos) { Logger.logMessage(".", false); statistics.reset(); ExecCommands newExecCommands = new ExecCommands(); // Copy the colors from the last commands. // Bugfix [2628217] - Robot Colors don't stick between rounds. newExecCommands.copyColors(commands.get()); currentCommands = newExecCommands; int others = battle.countActiveParticipants() - (isAlive() ? 1 : 0); int numSentries = battle.countActiveSentries(); RobotStatus stat = HiddenAccess.createStatus(energy, x, y, bodyHeading, gunHeading, radarHeading, velocity, currentCommands.getBodyTurnRemaining(), currentCommands.getRadarTurnRemaining(), currentCommands.getGunTurnRemaining(), currentCommands.getDistanceRemaining(), gunHeat, others, numSentries, battle.getRoundNum(), battle.getNumRounds(), battle.getTime()); status.set(stat); robotProxy.startRound(currentCommands, stat); synchronized (isSleeping) { try { // Wait for the robot to go to sleep (take action) isSleeping.wait(waitMillis, waitNanos); } catch (InterruptedException e) { logMessage("Wait for " + getName() + " interrupted."); // Immediately reasserts the exception by interrupting the caller thread itself Thread.currentThread().interrupt(); } } if (!isSleeping() && !battle.isDebugging()) { logMessage("\n" + getName() + " still has not started after " + waitMillis + " ms... giving up."); } }
@Override protected void initializeRound() { super.initializeRound(); inactiveTurnCount = 0; // Start robots long waitMillis; int waitNanos; if (isDebugging()) { waitMillis = DEBUG_TURN_WAIT_MILLIS; waitNanos = 0; } else { long waitTime = Math.min(300 * cpuConstant, 10000000000L); waitMillis = waitTime / 1000000; waitNanos = (int) (waitTime % 1000000); } for (RobotPeer robotPeer : getRobotsAtRandom()) { robotPeer.startRound(waitMillis, waitNanos); } Logger.logMessage(""); // puts in a new-line in the log message final ITurnSnapshot snapshot = new TurnSnapshot(this, robots, bullets, false); eventDispatcher.onRoundStarted(new RoundStartedEvent(snapshot, getRoundNum())); }
public void reload(boolean rebuild) { // Bug fix [2867326] - Lockup on start if too many bots in robots dir (cont'd). URLJarCollector.enableGc(true); URLJarCollector.gc(); if (rebuild) { Logger.logMessage("Rebuilding robot database..."); repository = new Repository(); } else if (repository == null) { setStatus("Reading robot database"); repository = load(); if (repository == null) { setStatus("Building robot database"); repository = new Repository(); } } refresh(true); setStatus(""); }