View Javadoc

1   /**
2    * Emohawk Bot, an implementation of the environment interface standard that 
3    * facilitates the connection between GOAL and Emohawk. 
4    * 
5    * Copyright (C) 2012 Emohawk Bot authors.
6    * 
7    * This program is free software: you can redistribute it and/or modify it under
8    * the terms of the GNU General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10   * version.
11   * 
12   * This program is distributed in the hope that it will be useful, but WITHOUT
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15   * details.
16   * 
17   * You should have received a copy of the GNU General Public License along with
18   * this program. If not, see <http://www.gnu.org/licenses/>.
19   */
20  
21  package nl.tudelft.goal.emohawk.environment;
22  
23  import java.util.HashMap;
24  
25  import nl.tudelft.goal.emohawk.agent.EmohawkBotBehavior;
26  import nl.tudelft.goal.emohawk.translators.EmoticonTypeTranslator;
27  import nl.tudelft.goal.emohawk.translators.PerceptTranslator;
28  import nl.tudelft.goal.emohawk.translators.PlaceTranslator;
29  import nl.tudelft.goal.emohawk.translators.UnrealIdOrLocationTranslator;
30  import nl.tudelft.goal.unreal.environment.AbstractUnrealEnvironment;
31  import nl.tudelft.goal.unreal.translators.LocationTranslator;
32  import nl.tudelft.goal.unreal.translators.RotationTranslator;
33  import nl.tudelft.goal.unreal.translators.TeamTranslator;
34  import nl.tudelft.goal.unreal.translators.UnrealIdTranslator;
35  import nl.tudelft.goal.unreal.translators.VelocityTranslator;
36  import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController;
37  import eis.eis2java.handlers.ActionHandler;
38  import eis.eis2java.handlers.AllPerceptPerceptHandler;
39  import eis.eis2java.handlers.DefaultActionHandler;
40  import eis.eis2java.handlers.PerceptHandler;
41  import eis.eis2java.translation.Translator;
42  import eis.eis2java.util.AllPerceptsProvider;
43  import eis.exceptions.EntityException;
44  import eis.exceptions.ManagementException;
45  import eis.iilang.Identifier;
46  import eis.iilang.Parameter;
47  import eis.iilang.ParameterList;
48  
49  public class EmohawkEnvironment extends AbstractUnrealEnvironment {
50  
51  	/**
52  	 * Generated serialVersionUID.
53  	 */
54  	private static final long serialVersionUID = 8240549393243585632L;
55  
56  	@Override
57  	protected void registerTranslators() {
58  
59  		Translator translator = Translator.getInstance();
60  
61  		/*
62  		 * Translators provided by the BaseUnrealEnvironment.
63  		 * 
64  		 * Please list these in lexical order.
65  		 */
66  
67  		LocationTranslator locationTranslator = new LocationTranslator();
68  		translator.registerJava2ParameterTranslator(locationTranslator);
69  		translator.registerParameter2JavaTranslator(locationTranslator);
70  
71  		/*
72  		 * To translate from Parameter2Java we are given an UnrealId. However we
73  		 * can not access the agents memory during translation. To work around
74  		 * this we store everything we have send to any agent. Hence the same
75  		 * object has to be used for both directions.
76  		 */
77  		RotationTranslator rotationTranslator = new RotationTranslator();
78  		translator.registerJava2ParameterTranslator(rotationTranslator);
79  		translator.registerParameter2JavaTranslator(rotationTranslator);
80  
81  		TeamTranslator teamTranslator = new TeamTranslator();
82  		translator.registerJava2ParameterTranslator(teamTranslator);
83  		translator.registerParameter2JavaTranslator(teamTranslator);
84  
85  		UnrealIdTranslator unrealIdTranslator = new UnrealIdTranslator();
86  		translator.registerJava2ParameterTranslator(unrealIdTranslator);
87  		translator.registerParameter2JavaTranslator(unrealIdTranslator);
88  
89  		VelocityTranslator velocityTranslator = new VelocityTranslator();
90  		translator.registerJava2ParameterTranslator(velocityTranslator);
91  		translator.registerParameter2JavaTranslator(velocityTranslator);
92  
93  		/*
94  		 * Translators provided by the EmohawkBot environment.
95  		 * 
96  		 * Please list these in lexical order.
97  		 */
98  
99  		EmoticonTypeTranslator emoticonTypeTranslator = new EmoticonTypeTranslator();
100 		translator.registerJava2ParameterTranslator(emoticonTypeTranslator);
101 		translator.registerParameter2JavaTranslator(emoticonTypeTranslator);
102 
103 		PerceptTranslator perceptTranslator = new PerceptTranslator();
104 		translator.registerJava2ParameterTranslator(perceptTranslator);
105 		
106 		PlaceTranslator placeTranslator = new PlaceTranslator();
107 		translator.registerJava2ParameterTranslator(placeTranslator);
108 
109 		UnrealIdOrLocationTranslator unrealIdOrLocationTranslator = new UnrealIdOrLocationTranslator();
110 		translator.registerParameter2JavaTranslator(unrealIdOrLocationTranslator);
111 
112 	}
113 
114 	public static void main(String[] args) throws ManagementException {
115 		HashMap<String, Parameter> map = new HashMap<String, Parameter>();
116 		map.put("botNames", new ParameterList(new Identifier("Test")));
117 		new EmohawkEnvironment().init(map);
118 
119 	}
120 
121 	@Override
122 	protected Class<EmohawkBotBehavior> getControlerClass() {
123 		return EmohawkBotBehavior.class;
124 	}
125 
126 	@Override
127 	protected PerceptHandler createPerceptHandler(UT2004BotController controller) throws EntityException {
128 		return new AllPerceptPerceptHandler((AllPerceptsProvider) controller);
129 	}
130 
131 	@Override
132 	protected ActionHandler createActionHandler(UT2004BotController controller) throws EntityException {
133 		return new DefaultActionHandler(controller);
134 	}
135 
136 }