[Pogamut-list] Bots standing around doing nothing

jacob.schrum pogamut-forum at diana.ms.mff.cuni.cz
Mon Nov 22 04:02:23 CET 2010


Re: Bots standing around doing nothing

Author: jacob.schrum

Here are the answers:

1) When I was initially troubleshooting, I was getting an error associated with calling bot.kill() and bot.stop() from within the bot. The error said that the kill command should be run from a Thread other than the one running the bot. Therefore, I created the following class:
-------------------------------------------------------------------------------------------------
    public class BotKiller extends Thread {

        private final BaseBot b;

        public BotKiller(BaseBot b) {
            this.b = b;
        }

        @Override
        public void run() {
            System.out.println("Killing " + b);
            //b.bot.kill();
            b.bot.stop();
            System.out.println("Done killing " + b);
        }
    }
--------------------------------------------------------------------------------------------
As you can see from the comment, I've stopped using kill() and only use stop(), so running a separate Thread may no longer be necessary. BaseBot is a super class of all of my bot classes.

2) I completely shutdown the server and kill/stop all of the bots. The reason for this is that I want to guarantee a fresh start. I've noticed that if I simply reload bots into the same server instance, there is sometimes a problem on the UT side where the bot body lingers in the game after it has been disconnected. However, simply replacing the "brains" of constantly running bots might be a viable option.

3) I'm not entirely sure this is the source of the problem. However, when I watch several separate evaluations, they mostly seem to be running fine, until after the point where I see an error (I have tracked down and fixed previous errors/exceptions before this one). After the error, if I log in to watch the bots, then their movement is stunted.

4) I'm pretty sure this error only happens when the bot is being stopped.

5) I want to mess around with the code a bit before I send it off. I'm still trying some ideas on my own. However, there is one snippet I'd like you to look at. I'm not using the StoryControlServer class yet. I'm still running things my own way, simply because I've been using it for so long; I've been able to make stuff work before by using small populations and periodically resuming from a checkpoint, but I want to use larger populations, and this error is preventing me from finishing a single generation. Anyway, here is how I start and restart the server:
-----------------------------------------------------------------------------------
MyUCCWrapper.MyUCCWrapperConf config = new MyUCCWrapper.MyUCCWrapperConf();
/* setup config */        
MyUCCWrapper ucc = new MyUCCWrapper(config);

        UT2004Server server = ucc.getUTServer();
        System.out.println("Confirming empty server");
        while (server.getAgents().size() > 0) {
            try {
                System.out.println("NOT EMPTY! RESET!");
                server.kill();
                Process p = ucc.getProcess();
                ucc.stop();
                p.destroy();
                synchronized (this) {
                    this.wait(1000);
                }
            } catch (InterruptedException ex) {
                ex.printStackTrace();
                System.out.println("Wait to reset interrupted");
            } catch (Exception e) {
                System.out.println("Mysterious exception");
                e.printStackTrace();
                System.out.println(e);
            } finally {
                ucc = new MyUCCWrapper(config);
                server = ucc.getUTServer();
            }
        }
        //Server was launched?
        System.out.println("Launch bots on empty server");

        try {
        /* This line uses the MultipleBotLauncher to launch my bot and five Hunters.
         * It keeps track of the length of evaluation, and launches Threads to kill/stop all bots  
         * when the eval time is up.
         */
            HunterNetwork.launchBot((TWEANNController) descriptor.controllers[0], Hunter.class, 5);
        } finally {
            while (true) {
                try {
                    server.stop(); // An exception here would skip the break
                    break;
                } catch (ComponentCantStopException ex) {
                    System.out.println("SERVER COMPONENT CAN'T STOP! TRY AGAIN!");
                    ex.printStackTrace();
                }
            }
            //server.kill();
            try {
                System.out.println("Server should be stopped");
                //server.stop();
                Process p = ucc.getProcess();
                ucc.stop();
                p.destroy();
            } finally {
                try {
                    synchronized (this) {
                        this.wait(1000);
                    }
                } catch (InterruptedException ex) {
                    System.out.println("Post-server-stop wait interrupted");
                    Logger.getLogger(LocalBaseExperimentExecutorImpl.class.getName()).log(Level.SEVERE, null, ex);
                    ex.printStackTrace();
                }
            }
        }
----------------------------------------------------------------------------------
6) As indicated in the comment above, each evaluation involves my bot and 5 Hunters for a total of 6.

I'll wait for your reply to this post to see if you have any more insights. If we still can't figure it out, I'll send you all of my code to muck through.

-Jacob

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=4&comments_reply_threadId=4&comments_parentId=404&post_reply=1#form>





More information about the Pogamut-list mailing list