Can bots run multiple threads?
Can bots run multiple threads?
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...
I think this might help with time-intensive calculations that could span turns...
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?
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?
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?
edit: better?
Last edited by guest on Wed Sep 26, 2007 12:30 pm, edited 1 time in total.
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.
Can anybody translate this for me?
I'm sure Black Pope could help me...
- Black Pope
- Lux Exorcist
- Posts: 3878
- Joined: Tue Sep 06, 2005 5:36 pm
- Location: God's Right Hand
Sure, Sun. Allow me to apply my formitable intellect and unsurpassed computer knowledge to make the following post understandable to you:
Should be read as follows: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.
Hope this helps!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.
- Black Pope
- Lux Exorcist
- Posts: 3878
- Joined: Tue Sep 06, 2005 5:36 pm
- Location: God's Right Hand
Ok on review that wasn't the best reply.
How about some pseudo code.
http://java.sun.com/j2se/1.3/docs/api/j ... hread.html
http://java.sun.com/j2se/1.5.0/docs/api ... phore.html
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.5.0/docs/api ... phore.html
Who is online
Users browsing this forum: No registered users and 56 guests