Can bots run multiple threads?

AI discussion, ideas, and SDK help.
Post Reply
User avatar
SunTzu
Lux Cartographer
Posts: 1586
Joined: Sat Jan 14, 2006 1:48 am
Location: Maryland

Can bots run multiple threads?

Post by SunTzu » Tue Sep 25, 2007 4:02 pm

I'm learning about concurrency in Java programming, and I was wondering if it's possible to have multiple threads running for each instance of a bot.

I think this might help with time-intensive calculations that could span turns...

User avatar
dustin
Lux Creator
Lux Creator
Posts: 10998
Joined: Thu May 15, 2003 2:01 am
Location: Cascadia
Contact:

Post by dustin » Tue Sep 25, 2007 4:38 pm

Yep, it's possible. You should only make command calls to the Board on the thread that Lux calls into the agent on though.

User avatar
SunTzu
Lux Cartographer
Posts: 1586
Joined: Sat Jan 14, 2006 1:48 am
Location: Maryland

Post by SunTzu » Tue Sep 25, 2007 5:04 pm

Cool!

I'm creating bot that uses other bots (like Chimera) but whenever I call the other agent's methods, I want to be able to create a timeout.

That way if the other bot gets into an endless loop, I can simply skip to the next method in my bot.

Since I would have to create a new thread that runs the other bot's method, it goes against your caution about only making calls to the Board via the first thread. Is there a safe way to handle this?

User avatar
guest
Luxer
Posts: 189
Joined: Fri Dec 17, 2004 9:17 pm
Location: Southern NH

Post by guest » Wed Sep 26, 2007 8:50 am

Subclass Board to make your own so the bot in the thread calls it instead of the lux board and it stores the arguments and then blocks. The main bot then makes the call to the real Board and stores the result in the subclass. The subclass then unblocks and returns the result it was given by main bot.


edit: better?
Last edited by guest on Wed Sep 26, 2007 12:30 pm, edited 1 time in total.

User avatar
SunTzu
Lux Cartographer
Posts: 1586
Joined: Sat Jan 14, 2006 1:48 am
Location: Maryland

Post by SunTzu » Wed Sep 26, 2007 8:59 am

guest wrote:Subclass Board to make your own so the bot in the thread calls is and it stored the result and then blocks. The main bot then makes the call to the real Board and stores the result in the subclass. The subclass then unblocks and the method returns.
:smt017
Can anybody translate this for me?

I'm sure Black Pope could help me...

User avatar
Black Pope
Lux Exorcist
Posts: 3878
Joined: Tue Sep 06, 2005 5:36 pm
Location: God's Right Hand

Post by Black Pope » Wed Sep 26, 2007 10:36 am

Sure, Sun. Allow me to apply my formitable intellect and unsurpassed computer knowledge to make the following post understandable to you:

guest wrote:Subclass Board to make your own so the bot in the thread calls is and it stored the result and then blocks. The main bot then makes the call to the real Board and stores the result in the subclass. The subclass then unblocks and the method returns.
Should be read as follows:
guest wrote:You need to run the mainline through a jerry rigged, coterized loophole. This should allow the inline spects to flush through the carborator. Be sure and aline all your gazinta perpendicular to the tangent. Thus, in the end, its is conceivable that the the damn thing will work.
Hope this helps!

User avatar
SunTzu
Lux Cartographer
Posts: 1586
Joined: Sat Jan 14, 2006 1:48 am
Location: Maryland

Post by SunTzu » Wed Sep 26, 2007 10:47 am

:smt044 Thanks Pope!

Now can somebody translate what the pretty, pretty flower translated? I have a hard time understanding Redneckese...

User avatar
Black Pope
Lux Exorcist
Posts: 3878
Joined: Tue Sep 06, 2005 5:36 pm
Location: God's Right Hand

Post by Black Pope » Wed Sep 26, 2007 11:05 am

DRIFTER! CLEAN UP ON AISLE FIVE!!!

User avatar
guest
Luxer
Posts: 189
Joined: Fri Dec 17, 2004 9:17 pm
Location: Southern NH

Post by guest » Wed Sep 26, 2007 12:28 pm

Ok on review that wasn't the best reply.
How about some pseudo code.

Code: Select all

Class ThreadedBoard
{
   m_Function
   m_Arguments
   m_Result
   m_bReturn

   PutArmies( ... )
  {
      m_Function = "PutArmies"
     m_Arguments = ...
     
     m_bReturn = false;
     while ( !m_bReturn )
         Thread.yield();

     return m_Result;
  }
}

Class MasterBot
{
   ThreadedBoard m_tBoard
   m_InnerBot( m_tBoard )
   PlaceArmies( .... )
   {
      thread.run( m_InnerBot.PlaceArmies( ... )
      while ( thread.isAlive() )   <-- timeout would go here
     {
          if ( m_tBoard.m_Function == "PutArmies" )
{
            m_tBoard.m_Result = m_luxBoard.PutArmies( m_tBoard.m_Arguments );
           m_tBoard.m_bReturn = true;
           thread.resume();
}
      }
   }
}
http://java.sun.com/j2se/1.3/docs/api/j ... hread.html
http://java.sun.com/j2se/1.5.0/docs/api ... phore.html

Post Reply

Who is online

Users browsing this forum: No registered users and 56 guests