Ejemplo n.º 1
0
 public static void WaitForStopThread()
 {
     try
     {
         if (!robotThread.Join(1000))
         {
             LoggerN.logError("Unable to stop thread for " + statics.getName());
             robotPeer.punishBadBehavior(BadBehavior.UNSTOPPABLE);
             robotPeer.setRunning(false);
         }
     }
     catch (Exception ex)
     {
         LoggerN.logError(ex);
         throw;
     }
 }
Ejemplo n.º 2
0
        public void run()
        {
            peer.setRunning(true);

            if (robotSpecification.isValid() && loadRobotRound())
            {
                try
                {
                    if (robot != null)
                    {
//                        peer.setRunning(true); // Does not work with .NET version

                        // Process all events for the first turn.
                        // This is done as the first robot status event must occur before the robot
                        // has started running.
                        eventManager.ProcessEvents();

                        // Call user code
                        CallUserCode();
                    }

                    // noinspection InfiniteLoopStatement
                    for (;;)
                    {
                        executeImpl();
                    }
                }
                catch (WinException)
                {
                    // Do nothing
                }
                catch (AbortedException)
                {
                    // Do nothing
                }
                catch (DeathException)
                {
                    println("SYSTEM: " + statics.getName() + " has died");
                }
                catch (DisabledException e)
                {
                    drainEnergy();

                    string msg = e.getMessage();
                    if (msg == null)
                    {
                        msg = "";
                    }
                    else
                    {
                        msg = ": " + msg;
                    }
                    println("SYSTEM: Robot disabled: " + msg);
                    LoggerN.logMessage("Robot disabled: " + statics.getName());
                }
                catch (SecurityException e)
                {
                    punishSecurityViolation(statics.getName() + " Exception: " + e);
                }
                catch (Exception e)
                {
                    if (e.InnerException is SecurityException)
                    {
                        punishSecurityViolation(statics.getName() + " " + e.InnerException + " Exception: " + e);
                    }
                    else
                    {
                        drainEnergy();
                        println(e);
                        LoggerN.logMessage(statics.getName() + ": Exception: " + e); // without stack here
                    }
                }
                finally
                {
                    waitForBattleEndImpl();
                }
            }
            else
            {
                drainEnergy();
                peer.punishBadBehavior(BadBehavior.CANNOT_START);
                waitForBattleEndImpl();
            }

            peer.setRunning(false);
        }