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 cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController;
26  
27  import nl.tudelft.goal.EIS2Java.handlers.ActionHandler;
28  import nl.tudelft.goal.EIS2Java.handlers.AsynchronousEntity;
29  import nl.tudelft.goal.EIS2Java.handlers.PerceptHandler;
30  import nl.tudelft.goal.EIS2Java.handlers.SynchronizedActionHandler;
31  import nl.tudelft.goal.EIS2Java.handlers.SynchronizedPerceptHandler;
32  import nl.tudelft.goal.EIS2Java.translation.Translator;
33  import nl.tudelft.goal.emohawk.agent.EmohawkBotBehavior;
34  import nl.tudelft.goal.emohawk.translators.AgentInfoTranslator;
35  import nl.tudelft.goal.emohawk.translators.AnimTypeTranslator;
36  import nl.tudelft.goal.emohawk.translators.EmoticonTypeTranslator;
37  import nl.tudelft.goal.emohawk.translators.GameTranslator;
38  import nl.tudelft.goal.emohawk.translators.PlaceTranslator;
39  import nl.tudelft.goal.emohawk.translators.PlayerTranslator;
40  import nl.tudelft.goal.emohawk.translators.UnrealIdOrLocationTranslator;
41  import nl.tudelft.goal.unreal.environment.AbstractUnrealEnvironment;
42  import nl.tudelft.goal.unreal.translators.LocationTranslator;
43  import nl.tudelft.goal.unreal.translators.NavPointTranslator;
44  import nl.tudelft.goal.unreal.translators.RotationTranslator;
45  import nl.tudelft.goal.unreal.translators.TeamTranslator;
46  import nl.tudelft.goal.unreal.translators.UnrealIdTranslator;
47  import nl.tudelft.goal.unreal.translators.VelocityTranslator;
48  import eis.exceptions.EntityException;
49  import eis.exceptions.ManagementException;
50  import eis.iilang.Identifier;
51  import eis.iilang.Parameter;
52  import eis.iilang.ParameterList;
53  
54  public class EmohawkEnvironment extends AbstractUnrealEnvironment {
55  
56  	/**
57  	 * Generated serialVersionUID.
58  	 */
59  	private static final long serialVersionUID = 8240549393243585632L;
60  
61  	@Override
62  	protected void registerTranslators() {
63  
64  		Translator translator = Translator.getInstance();
65  
66  		/*
67  		 * Translators provided by the BaseUnrealEnvironment.
68  		 * 
69  		 * Please list these in lexical order.
70  		 */
71  
72  		LocationTranslator locationTranslator = new LocationTranslator();
73  		translator.registerJava2ParameterTranslator(locationTranslator);
74  		translator.registerParameter2JavaTranslator(locationTranslator);
75  
76  		/*
77  		 * To translate from Parameter2Java we are given an UnrealId. However we
78  		 * can not access the agents memory during translation. To work around
79  		 * this we store everything we have send to any agent. Hence the same
80  		 * object has to be used for both directions.
81  		 */
82  		NavPointTranslator navPointTranslator = new NavPointTranslator();
83  		translator.registerJava2ParameterTranslator(navPointTranslator);
84  		translator.registerParameter2JavaTranslator(navPointTranslator);
85  
86  		RotationTranslator rotationTranslator = new RotationTranslator();
87  		translator.registerJava2ParameterTranslator(rotationTranslator);
88  		translator.registerParameter2JavaTranslator(rotationTranslator);
89  
90  		TeamTranslator teamTranslator = new TeamTranslator();
91  		translator.registerJava2ParameterTranslator(teamTranslator);
92  		translator.registerParameter2JavaTranslator(teamTranslator);
93  
94  		UnrealIdTranslator unrealIdTranslator = new UnrealIdTranslator();
95  		translator.registerJava2ParameterTranslator(unrealIdTranslator);
96  		translator.registerParameter2JavaTranslator(unrealIdTranslator);
97  
98  		VelocityTranslator velocityTranslator = new VelocityTranslator();
99  		translator.registerJava2ParameterTranslator(velocityTranslator);
100 		translator.registerParameter2JavaTranslator(velocityTranslator);
101 
102 		/*
103 		 * Translators provided by the EmohawkBot environment.
104 		 * 
105 		 * Please list these in lexical order.
106 		 */
107 		AgentInfoTranslator agentInfoTranslator = new AgentInfoTranslator();
108 		translator.registerJava2ParameterTranslator(agentInfoTranslator);
109 
110 		AnimTypeTranslator animTypeTranslator = new AnimTypeTranslator();
111 		translator.registerJava2ParameterTranslator(animTypeTranslator);
112 		translator.registerParameter2JavaTranslator(animTypeTranslator);
113 
114 		EmoticonTypeTranslator emoticonTypeTranslator = new EmoticonTypeTranslator();
115 		translator.registerJava2ParameterTranslator(emoticonTypeTranslator);
116 		translator.registerParameter2JavaTranslator(emoticonTypeTranslator);
117 
118 		GameTranslator gameTranslator = new GameTranslator();
119 		translator.registerJava2ParameterTranslator(gameTranslator);
120 		
121 		PlaceTranslator placeTranslator = new PlaceTranslator();
122 		translator.registerJava2ParameterTranslator(placeTranslator);
123 		
124 		PlayerTranslator playerTranslator = new PlayerTranslator();
125 		translator.registerJava2ParameterTranslator(playerTranslator);
126 		
127 		UnrealIdOrLocationTranslator unrealIdOrLocationTranslator = new UnrealIdOrLocationTranslator();
128 		translator.registerParameter2JavaTranslator(unrealIdOrLocationTranslator);
129 
130 	}
131 
132 	public static void main(String[] args) throws ManagementException {
133 		HashMap<String, Parameter> map = new HashMap<String, Parameter>();
134 		map.put("botNames", new ParameterList(new Identifier("Test")));
135 		new EmohawkEnvironment().init(map);
136 
137 	}
138 
139 	@Override
140 	protected Class<EmohawkBotBehavior> getControlerClass() {
141 		return EmohawkBotBehavior.class;
142 	}
143 
144 	@Override
145 	protected PerceptHandler createPerceptHandler(UT2004BotController controller) throws EntityException {
146 		return new SynchronizedPerceptHandler((AsynchronousEntity) controller);
147 	}
148 
149 	@Override
150 	protected ActionHandler createActionHandler(UT2004BotController controller) throws EntityException {
151 		return new SynchronizedActionHandler((AsynchronousEntity) controller);
152 	}
153 
154 }