ITurnSnapshot readSnapshot(int currentTime) { if (objectReadStream == null) { return null; } try { // TODO implement seek to currentTime, warn you. turns don't have same size in bytes return (ITurnSnapshot) objectReadStream.readObject(); } catch (EOFException e) { logError(e); return null; } catch (Exception e) { logError(e); return null; } }
private static void deleteFile(String filename) { Logger.logMessage("Deleting " + filename + "..."); try { recursivelyDelete(new File(filename)); } catch (IOException ex) { Logger.logError(ex.getMessage()); } }
public void cleanup() { try { if (runThread == null || !runThread.isAlive()) { if (!discardAWT()) { runThreadGroup.destroy(); } } else { Logger.logWarning("Could not destroy " + runThread.getName()); } } catch (Exception e) { Logger.logError("Could not destroy " + runThreadGroup.getName(), e); } }
public static void logError(String message, Throwable t) { logError(message + ":\n" + toStackTraceString(t)); }
protected void preloadRound() { logMessage("----------------------"); Logger.logMessage("Round " + (roundNum + 1) + " initializing..", false); }
/** * @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; }
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(); }
/** * Logs a warning that the deterministic random feature is not supported by the * JVM. */ private static void logWarningNotSupported() { if (!(warningNotSupportedLogged || System.getProperty("RANDOMSEED", "none").equals("none"))) { logWarning("The deterministic random generator feature is not supported by this JVM:\n" + System.getProperty("java.vm.vendor") + " " + System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version")); warningNotSupportedLogged = true; } } }
private void notSupportedWarn() { Logger.printlnToRobotsConsole("SYSTEM: We are sorry. Operation is not supported in Robocode."); }
public BattleManager(ISettingsManager properties, IRepositoryManager repositoryManager, IHostManager hostManager, ICpuManager cpuManager, BattleEventDispatcher battleEventDispatcher, IRecordManager recordManager) { // NO_UCD (unused code) this.properties = properties; this.recordManager = recordManager; this.repositoryManager = repositoryManager; this.cpuManager = cpuManager; this.hostManager = hostManager; this.battleEventDispatcher = battleEventDispatcher; Logger.setLogListener(battleEventDispatcher); battleProperties = new BattleProperties(properties); }
protected void initializeRound() { logMessage(""); logMessage("Let the games begin!"); roundOver = false; endTimer = 0; currentTime = 0; }
public static void logError(Throwable t) { logError(toStackTraceString(t)); }
public void saveWindowPositions() { FileOutputStream out = null; try { out = new FileOutputStream(FileUtil.getWindowConfigFile()); getWindowPositions().store(out, "Robocode window sizes"); } catch (IOException e) { Logger.logWarning("Unable to save window positions: " + e); } finally { if (out != null) { try { out.close(); } catch (IOException ignored) {} } } }
/** * Changes the time when this event occurred. * <p> * Note that the time is equal to the turn of a battle round. * <p> * This method is intended for letting robot developers create their own event types. * It is not possible to change the time of an event after it has been added to the event * queue of the robot. * * @param newTime the time this event occurred */ public void setTime(long newTime) { if (addedToQueue) { Logger.printlnToRobotsConsole( "SYSTEM: The time of an event cannot be changed after it has been added the event queue."); } else { time = newTime; } }
public void uncaughtException(Thread t, Throwable e) { Logger.logError("UncaughtException on thread " + t.getClass(), e); } });
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 static void logWarning(String s) { logMessage("Warning: " + s, true); }
deleteDir(file); if (file.exists() && !file.delete()) { Logger.logError("Cannot delete: " + file); Logger.logWarning(file + " may be a symlink. Ignoring."); Logger.logWarning("Cannot determine canonical file for " + file + ". Ignoring."); Logger.logError("Cannot delete: " + file);
/** * Hidden method for setting the priority from the game engine without checking for the 'addedToQueue' flag. * <p> * <strong>Notice:</strong> This method is called by the game engine only. * * @param newPriority the new priority of this event. */ // This method must be invisible on Robot API private void setPriorityHidden(int newPriority) { if (newPriority < 0) { Logger.printlnToRobotsConsole("SYSTEM: Priority must be between 0 and 99"); Logger.printlnToRobotsConsole("SYSTEM: Priority for " + this.getClass().getName() + " will be 0"); newPriority = 0; } else if (newPriority > 99) { Logger.printlnToRobotsConsole("SYSTEM: Priority must be between 0 and 99"); Logger.printlnToRobotsConsole("SYSTEM: Priority for " + this.getClass().getName() + " will be 99"); newPriority = 99; } priority = newPriority; }