View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.analyzer;
2   
3   import java.util.Map;
4   
5   import cz.cuni.amis.pogamut.base.agent.IAgentId;
6   import cz.cuni.amis.pogamut.base.agent.params.IAgentParameters;
7   import cz.cuni.amis.pogamut.base.communication.connection.IWorldConnectionAddress;
8   import cz.cuni.amis.pogamut.base.communication.connection.impl.socket.SocketConnectionAddress;
9   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
10  import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
11  import cz.cuni.amis.pogamut.ut2004.factory.guice.remoteagent.UT2004ObserverModule;
12  
13  /**
14   * Agent parameters are meant to provide run-time parameters needed by {@link UT2004Analyzer}.
15   * <p><p>
16   * Crucial parameters that (even though are present in the {@link UT2004AnalyzerRunner} might be needed
17   * in order to customize whole {@link UT2004Analyzer}: {@link UT2004AnalyzerParameters#setObserverModule(UT2004AnalyzerObserverModule).
18   * <p><p>
19   * NOTE: all {@link IAgentParameters} implementors are usually used together with {@link IAgentRunner} or {@link IMultipleAgentRunner}
20   * which usually contains sensible default params, therefore there is no need to set all parameters
21   * into newly created ones as runners will supply them via {@link IAgentParameters#assignDefaults(IAgentParameters)}.
22   *
23   * @see UT2004AgentParameters
24   * @author Jimmy
25   */
26  /**
27   * @author Jimmy
28   *
29   */
30  public class UT2004AnalyzerParameters extends UT2004AgentParameters {
31  
32  	private SocketConnectionAddress observerAddress;
33  	private UT2004AnalyzerFullObserverModule observerModule;
34  	private String outputPath;
35  	private Boolean waitForMatchRestart = null;
36  	private Map<UnrealId, String> fileNames = null;
37  	private Boolean humanLikeObserving = null;
38  	
39  	/**
40  	 * If you need to populate the parameters after instantiation, use setters available in this
41  	 * class: {@link UT2004AnalyzerParameters#setAgentId(IAgentId)}, {@link UT2004AnalyzerParameters#setWorldAddress(IWorldConnectionAddress)},
42  	 * {@link UT2004AnalyzerParameters#setObserverModule(UT2004ObserverModule)}.
43  	 */
44  	public UT2004AnalyzerParameters() {
45  		super();
46  	}
47  
48  	public UT2004AnalyzerFullObserverModule getObserverModule() {
49  		return observerModule;
50  	}
51  
52  	/**
53  	 * Sets observer module (one that will be used to construct new {@link UT2004AnalyzerObserver} in 
54  	 * order to sniff info about connected bots.
55  	 * <p><p>
56  	 * WARNING: Note that you should not mess with 'setters' in different threads as they
57  	 * are non-thread-safe and may interrupt horrible agent instantiations with such behavior.
58  	 * @param address
59  	 * @return this instance
60  	 */
61  	public UT2004AnalyzerParameters setObserverModule(UT2004AnalyzerFullObserverModule observerModule) {
62  		this.observerModule = observerModule;
63  		return this;
64  	}
65  	
66  	@Override
67  	public UT2004AnalyzerParameters setAgentId(IAgentId agentId) {
68  		super.setAgentId(agentId);
69  		return this;
70  	}
71  	
72  	@Override
73  	public UT2004AnalyzerParameters setWorldAddress(IWorldConnectionAddress address) {
74  		super.setWorldAddress(address);
75  		return this;
76  	}
77  	
78  	/**
79  	 * Contains path to directory where the observer should output its results. MUST POINT TO DIR!
80  	 * @return
81  	 */
82  	public String getOutputPath() {
83  		return outputPath;
84  	}
85  
86  	/**
87  	 * Sets path to directory where the observer should output its results. MUST POINT TO DIR!
88  	 * @param outputPath
89  	 */
90  	public UT2004AnalyzerParameters setOutputPath(String outputPath) {
91  		this.outputPath = outputPath;
92  		return this;
93  	}
94  	
95  	/**
96  	 * Whether the analyzer's observers should wait for match-restart before it starts to collect data.
97  	 * @return
98  	 */
99  	public boolean isWaitForMatchRestart() {
100 		return waitForMatchRestart == null ? false : waitForMatchRestart;
101 	}
102 
103 	/**
104 	 * Sets whether the analyzer's observers should wait for match-restart before it starts to collect data.
105 	 * @param waitForMatchRestart
106 	 */
107 	public UT2004AnalyzerParameters setWaitForMatchRestart(boolean waitForMatchRestart) {
108 		this.waitForMatchRestart = waitForMatchRestart;
109 		return this;
110 	}	
111 	
112 	/**
113 	 * This may be used to provide concrete filenames for outputting stats for bots identified by their id.
114 	 * @return
115 	 */
116 	public Map<UnrealId, String> getFileNames() {
117 		return fileNames;
118 	}
119 
120 	/**
121 	 * This may be used to provide concrete filenames for outputting stats for bots identified by their id.
122 	 * @param fileNames
123 	 * @return
124 	 */
125 	public UT2004AnalyzerParameters setFileNames(Map<UnrealId, String> fileNames) {
126 		this.fileNames = fileNames;
127 		return this;
128 	}
129 
130 	/**
131 	 * Returns observer address that should be used for spawning new observers.
132 	 * @return
133 	 */
134 	public SocketConnectionAddress getObserverAddress() {
135 		return observerAddress;
136 	}
137 
138 	/**
139 	 * Sets observer address that should be used for spawning new observers. If you do not specify it a default address will be used.
140 	 * @param observerAddress
141 	 */
142 	public UT2004AnalyzerParameters setObserverAddress(SocketConnectionAddress observerAddress) {
143 		this.observerAddress = observerAddress;
144 		return this;
145 	}
146 
147 	/**
148 	 * Whether to produce logs for "HumanLikeBot project" analysis.
149 	 * @return
150 	 */
151 	public Boolean getHumanLikeObserving() {
152 		return humanLikeObserving;
153 	}
154 
155 	/**
156 	 * Whether to produce logs for "HumanLikeBot project" analysis.
157 	 * @param humanLikeObserving
158 	 */
159 	public UT2004AnalyzerParameters setHumanLikeObserving(Boolean humanLikeObserving) {
160 		this.humanLikeObserving = humanLikeObserving;
161 		return this;
162 	}
163 
164 	@Override
165 	public void assignDefaults(IAgentParameters defaults) {
166 		super.assignDefaults(defaults);
167 		if (defaults instanceof UT2004AnalyzerParameters) {
168 			if (observerModule == null) observerModule = ((UT2004AnalyzerParameters)defaults).getObserverModule();
169 			if (observerAddress == null) observerAddress = ((UT2004AnalyzerParameters)defaults).getObserverAddress();
170 			if (outputPath == null) outputPath = ((UT2004AnalyzerParameters)defaults).getOutputPath();
171 			if (waitForMatchRestart == null && ((UT2004AnalyzerParameters)defaults).waitForMatchRestart != null)
172 				waitForMatchRestart = ((UT2004AnalyzerParameters)defaults).waitForMatchRestart;
173 			if (fileNames == null && ((UT2004AnalyzerParameters)defaults).fileNames != null) {
174 				this.fileNames = ((UT2004AnalyzerParameters)defaults).fileNames;
175 			}
176 			if (humanLikeObserving == null) {
177 				humanLikeObserving = ((UT2004AnalyzerParameters)defaults).humanLikeObserving;
178 			}
179 		}
180 	}	
181 	
182 }