package edu.lehigh.insyte.ctp2_liet; import mil.navy.nrl.liet.EnvironmentRegistry; import mil.navy.nrl.liet.EnvironmentBuilder; import mil.navy.nrl.liet.data.Symbol; import mil.navy.nrl.liet.examples.TicTacToeAgent; import mil.navy.nrl.liet.examples.TicTacToeEnvironment; import mil.navy.nrl.liet.tieltadapters.TIELTModelEnvironmentAdapter; import tielt.data.file.GameInterfaceModel; import tielt.data.file.FailureReadingKnowledgeBaseException; import java.io.FileNotFoundException; import java.io.File; import utility.ExceptionHandler; import mil.navy.nrl.liet.OnlineExperimenter; /** *
Title:
* *Description: First attempt to port Joe's TIELT/CTP2 stuff to LIET
* *Copyright: Copyright (c) 2007
* *Company: Lehigh University, InSyTe Lab
* * @author sml3@lehigh.edu * @version 1.0 */ public class Main { //must be unique. consider checking that it is so with the registry. public static final Symbol TYPE_CTP2_GAME = Symbol.makeSymbol( "CTP2_GAME" ); //the next few variables are used in the creation of CTP2_envAdapter and EnvironmentBuilder, as well as registering with the EnvironmentRegistry protected static final String CTP2_SIM_INTERFACE_PATH = "Knowledge Bases\\Game Interface Models\\CTP_ver1.xml"; protected TIELTModelEnvironmentAdapter CTP2_envAdapter = null; protected EnvironmentBuilder CTP2_envBuilder = null; protected final ExceptionHandler HANDLER = ExceptionHandler.JUNIT_FAIL; protected static final String LAST_INIT_MESSAGE = "GameStarted"; //The last initialization message sent by the environment; no actions will be called until initialization is complete. protected static final String TURN_END_MESSAGE = "MyTurn"; //The name of the percept sent when the prior turn ends and the agent is allowed to act. protected static final String TURN_END_ACTION = "EndTurn"; //The name of the action the agents sends to signify the end of its turn. This action should cause simulation to resume. protected static final boolean COMPILE_ENV = false; public Main() { try { CTP2_envAdapter = TIELTModelEnvironmentAdapter. createTurnBasedFromModel(TYPE_CTP2_GAME, GameInterfaceModel.open(new File(CTP2_SIM_INTERFACE_PATH)), HANDLER, LAST_INIT_MESSAGE, TURN_END_MESSAGE, TURN_END_ACTION, COMPILE_ENV); } catch (FailureReadingKnowledgeBaseException e) { e.printStackTrace(); System.out.println( "Dying... maybe your KB loc is wrong?" ); System.exit(1); } try { CTP2_envBuilder = TIELTModelEnvironmentAdapter.getTurnBasedBuilder( TYPE_CTP2_GAME, CTP2_SIM_INTERFACE_PATH, HANDLER, LAST_INIT_MESSAGE, TURN_END_MESSAGE, TURN_END_ACTION); } catch (FailureReadingKnowledgeBaseException e) { e.printStackTrace(); System.out.println( "Dying... maybe your KB file is invalid?" ); System.exit(1); } catch (FileNotFoundException f) { f.printStackTrace(); System.out.println( "Dying... maybe your KB loc is wrong?" ); System.exit(1); } EnvironmentRegistry.getRegistry().registerEnvironmentBuilder( TYPE_CTP2_GAME, CTP2_envBuilder ); System.out.println( "Success in creating builder!" ); } public void testBasic() { OnlineExperimenter e = new OnlineExperimenter(ExceptionHandler.PRINT_STACK_TRACE_TO_STDERR); e.addAgentWithType(CTP2Agent.getBuilder()); e.setEnvironmentBuilder( CTP2_envBuilder ); e.setTrialCount(1); e.run(); e.waitForEnd(); } public static void main(String[] args) { Main main = new Main(); main.testBasic(); } }