cz.cuni.amis.pogamut.sposh.ut2004
Class SposhLogicController<BOT extends UT2004Bot,WORK_EXECUTOR extends IWorkExecutor>

Package class diagram package SposhLogicController
java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController<BOT>
      extended by cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicController<BOT>
          extended by cz.cuni.amis.pogamut.sposh.ut2004.SposhLogicController<BOT,WORK_EXECUTOR>
All Implemented Interfaces:
cz.cuni.amis.pogamut.base.agent.module.IAgentLogic<cz.cuni.amis.pogamut.base.agent.module.LogicModule>, IUT2004BotController<BOT>, IUT2004BotLogicController<BOT,cz.cuni.amis.pogamut.base.agent.module.LogicModule>
Direct Known Subclasses:
StateSposhLogicController

public abstract class SposhLogicController<BOT extends UT2004Bot,WORK_EXECUTOR extends IWorkExecutor>
extends UT2004BotLogicController<BOT>

Logic controller that utilizes sposh engine for decision making of bot in UT2004 environment.

Sposh requires two things: plan and primitives. The plan is provided by SposhLogicController#getPlan() method and are supplied by IWorkExecutor. IWorkExecutor is instantiated during first call of logic, so if the varioud modules are already initialized.

If needed, override createTimer(), but it shouldn't be needed.

Author:
Honza H.

Field Summary
static String SPOSH_LOG_CATEGORY
           
 
Fields inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicController
logicModule
 
Fields inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController
bot, log, USER_LOG_CATEGORY_ID
 
Constructor Summary
SposhLogicController()
           
 
Method Summary
protected  ITimer createTimer()
          Create timer for posh engine.
protected abstract  WORK_EXECUTOR createWorkExecutor()
          Create IWorkExecutor that will execute primitives contained in the plan.
protected  List<PoshEngine> getEngines()
          Get engines used by this bot.
protected  String getPlanFromFile(String filename)
          Read POSH plan from the file and return it.
protected  String getPlanFromResource(String resourcePath)
          Get POSh plan from resource int the same jar as the class.
protected  String getPlanFromStream(InputStream in)
          Read POSH plan from the stream and return it.
protected abstract  List<String> getPlans()
          Get all Yaposh plans this bot is supposed to execute.
protected  List<String> getPlansFromDirectory(String directoryPath)
          Reads all '.lap' file from specified directory.
protected  ITimer getTimer()
          Get timer that is used by posh engine to make sure timeouts and other stuff that requires time are working properly.
protected  WORK_EXECUTOR getWorkExecutor()
          Get work executor.
 void initializeController(BOT bot)
          .
 void logic()
          Logic method evaluates all Yaposh plans in same order as they were specified.
protected  void logicAfterPlan()
          Method that is triggered every time the plan for executor is evaluated.
protected  void logicBeforePlan()
          Method that is triggered every time the plan for executor is evaluated.
 
Methods inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicController
beforeFirstLogic, getLogicInitializeTime, getLogicShutdownTime, initializeLogic, logicInitialize, logicShutdown
 
Methods inherited from class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController
botFirstSpawn, botInitialized, botKilled, botShutdown, finishControllerInitialization, getAct, getBot, getInitializeCommand, getLog, getName, getPassword, getWorldView, prepareBot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController
botFirstSpawn, botInitialized, botKilled, botShutdown, finishControllerInitialization, getAct, getBot, getInitializeCommand, getLog, getPassword, getWorldView, prepareBot
 

Field Detail

SPOSH_LOG_CATEGORY

public static final String SPOSH_LOG_CATEGORY
See Also:
Constant Field Values
Constructor Detail

SposhLogicController

public SposhLogicController()
Method Detail

initializeController

public void initializeController(BOT bot)
. Yaposh egnines that will be used by this bot are created here (so getEngines() doesn't return empty list after this).

Specified by:
initializeController in interface IUT2004BotController<BOT extends UT2004Bot>
Overrides:
initializeController in class UT2004BotLogicController<BOT extends UT2004Bot>
Parameters:
bot -

createWorkExecutor

protected abstract WORK_EXECUTOR createWorkExecutor()
Create IWorkExecutor that will execute primitives contained in the plan. This method will be called only once.

Returns:
executor to execute primitives.

getWorkExecutor

protected final WORK_EXECUTOR getWorkExecutor()
Get work executor. If work executor is not yet created, create one using createWorkExecutor().

Returns:
work executor for this bot controller.

logic

public final void logic()
Logic method evaluates all Yaposh plans in same order as they were specified.

Specified by:
logic in interface cz.cuni.amis.pogamut.base.agent.module.IAgentLogic<cz.cuni.amis.pogamut.base.agent.module.LogicModule>
Overrides:
logic in class UT2004BotLogicController<BOT extends UT2004Bot>

logicBeforePlan

protected void logicBeforePlan()
Method that is triggered every time the plan for executor is evaluated. It is triggered right before the plan evaluation. Currently, it checks if workExecutor is a ILogicWorkExecutor and if it is, it executes ILogicWorkExecutor.logicBeforePlan().


logicAfterPlan

protected void logicAfterPlan()
Method that is triggered every time the plan for executor is evaluated. It is triggered right after the plan evaluation. Currently, it checks if workExecutor is a ILogicWorkExecutor and if it is, it executes ILogicWorkExecutor.logicBeforePlan().


createTimer

protected ITimer createTimer()
Create timer for posh engine. By default, use SystemClockTimer.

Returns:
See Also:
getTimer()

getTimer

protected final ITimer getTimer()
Get timer that is used by posh engine to make sure timeouts and other stuff that requires time are working properly.

Returns:

getEngines

protected final List<PoshEngine> getEngines()
Get engines used by this bot.

Returns:
Empty list if engine wasn't yet created(they are created in initializeController(UT2004Bot) ) or the engines.

getPlans

protected abstract List<String> getPlans()
                                  throws IOException
Get all Yaposh plans this bot is supposed to execute. The plans will be executed in same order as in the returned list. Easiest way is to use getPlanFromResource(java.lang.String), getPlanFromFile(java.lang.String), or {@link #getPlansFromDirectory(String)}. .

Returns:
List of sources of the plans
Throws:
IOException

getPlanFromStream

protected final String getPlanFromStream(InputStream in)
                                  throws IOException
Read POSH plan from the stream and return it. Close the stream.

Parameters:
in - Input stream from which the plan is going to be read
Returns:
Text of the plan, basically content of the stream
Throws:
IOException - If there is some error while reading the stream

getPlansFromDirectory

protected final List<String> getPlansFromDirectory(String directoryPath)
                                            throws IOException
Reads all '.lap' file from specified directory. They are alphabetically sorted (ascending order).

Parameters:
directoryPath -
Returns:
Throws:
IOException

getPlanFromFile

protected final String getPlanFromFile(String filename)
                                throws IOException
Read POSH plan from the file and return it.

Parameters:
filename - Path to the file that contains the POSH plan.
Returns:
Text of the plan, basically content of the file
Throws:
IOException - If there is some error while reading the stream

getPlanFromResource

protected final String getPlanFromResource(String resourcePath)
                                    throws IOException
Get POSh plan from resource int the same jar as the class.

  // Plan is stored in package cz.cuni.amis.pogamut.testbot under name poshPlan.lap
  // This can get the file from .jar or package structure
  getPlanFromResource("cz/cuni/amis/pogamut/testbot/poshPlan.lap");
 

Parameters:
resourcePath - Path to the plan in some package
Returns:
Content of the plan.
Throws:
IOException - if something goes wrong, like file is missing, hardisk has blown up ect.


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.