View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.analyzer;
2   
3   import java.io.PrintWriter;
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.unreal.communication.messages.UnrealId;
9   import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
10  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
11  
12  public class UT2004AnalyzerFullObserverParameters extends UT2004AgentParameters {
13  
14  	private String observedAgentId;
15  	
16  	private Boolean waitForMatchRestart = null;
17  	
18  	private String outputPath = null;
19  	
20  	private Boolean humanLike_observingEnabled = null;
21  	
22  	/**
23  	 * FileName to be used for the output. Must end with some file extension (e.g., .csv).
24  	 */
25  	private String fileName;
26  
27  	private PrintWriter humanLike_writer;
28  
29  	private String humanLike_botName;
30  	
31  	public UT2004AnalyzerFullObserverParameters() {
32  		super();
33  	}
34  
35  	/**
36  	 * Returns ID of the player that should be observed.
37  	 * @return
38  	 */
39  	public String getObservedAgentId() {
40  		return observedAgentId;
41  	}
42  
43  	/**
44  	 * Sets 'id' (usually taken from the {@link UnrealId} that is present for instance in {@link Self#getId()}) 
45  	 * of the bot that is going to be observed by newly created observer.
46  	 * <p><p>
47  	 * WARNING: Note that you should not mess with 'setters' in different threads as they
48  	 * are non-thread-safe and may interrupt horrible agent instantiations with such behavior.
49  	 * @param address
50  	 * @return this instance
51  	 */
52  	public UT2004AnalyzerFullObserverParameters setObservedAgentId(String observedAgentId) {
53  		this.observedAgentId = observedAgentId;
54  		return this;
55  	}
56  	
57  	@Override
58  	public UT2004AnalyzerFullObserverParameters setAgentId(IAgentId agentId) {
59  		super.setAgentId(agentId);
60  		return this;
61  	}
62  	
63  	@Override
64  	public UT2004AnalyzerFullObserverParameters setWorldAddress(IWorldConnectionAddress address) {
65  		super.setWorldAddress(address);
66  		return this;
67  	}
68  	
69  	/**
70  	 * Contains path to directory where the observer should output its results. MUST POINT TO DIR!
71  	 * @return
72  	 */
73  	public String getOutputPath() {
74  		return outputPath;
75  	}
76  
77  	/**
78  	 * Sets  path to directory where the observer should output its results. MUST POINT TO DIR!
79  	 * @param outputPath
80  	 */
81  	public UT2004AnalyzerFullObserverParameters setOutputPath(String outputPath) {
82  		this.outputPath = outputPath;
83  		return this;
84  	}
85  
86  	/**
87  	 * Whether the observer should wait for match-restart before it starts to collect data.
88  	 * @return
89  	 */
90  	public boolean isWaitForMatchRestart() {
91  		return waitForMatchRestart == null ? false : waitForMatchRestart;
92  	}
93  
94  	/**
95  	 * Sets whether the observer should wait for match-restart before it starts to collect data.
96  	 * @param waitForMatchRestart
97  	 */
98  	public UT2004AnalyzerFullObserverParameters setWaitForMatchRestart(boolean waitForMatchRestart) {
99  		this.waitForMatchRestart = waitForMatchRestart;
100 		return this;
101 	}	
102 	
103 	/**
104 	 * Returns file name that should be used for outputting data (just file name, must be combined with {@link UT2004AnalyzerObserver#getOutputFilePath()}.
105 	 * @return
106 	 */
107 	public String getFileName() {
108 		return fileName;
109 	}
110 
111 	/**
112 	 * Sets FileName to be used for the output. Must end with some file extension (e.g., .csv). (Just file name, will be combined with {@link UT2004AnalyzerObserver#getOutputFilePath()}.
113 	 * @param fileName
114 	 */
115 	public UT2004AnalyzerFullObserverParameters setFileName(String fileName) {
116 		this.fileName = fileName;
117 		return this;
118 	}
119 	
120 	/**
121 	 * Whether to produce additional output for "HumanLikeBot" project analysis.
122 	 * @return
123 	 */
124 	public Boolean isHumanLikeObservingEnabled() {
125 		return humanLike_observingEnabled;
126 	}
127 	
128 	public PrintWriter getHumanLikeWriter() {
129 		return humanLike_writer;
130 	}
131 	
132 	public String getHumanLikeBotName() {
133 		return humanLike_botName;
134 	}
135 
136 	public UT2004AnalyzerFullObserverParameters setHumanLikeObserving(String botName, PrintWriter humanLikeWriter) {
137 		this.humanLike_observingEnabled = humanLikeWriter != null;
138 		this.humanLike_botName = humanLikeWriter != null ? botName : null;		
139 		this.humanLike_writer = humanLikeWriter;
140 		return this;
141 	}
142 
143 	@Override
144 	public void assignDefaults(IAgentParameters defaults) {
145 		super.assignDefaults(defaults);
146 		if (defaults instanceof UT2004AnalyzerFullObserverParameters) {
147 			if (waitForMatchRestart == null && ((UT2004AnalyzerFullObserverParameters)defaults).waitForMatchRestart != null)
148 				waitForMatchRestart = ((UT2004AnalyzerFullObserverParameters)defaults).waitForMatchRestart;
149 			if (outputPath == null) outputPath = ((UT2004AnalyzerFullObserverParameters)defaults).getOutputPath();
150 			if (fileName == null) fileName = ((UT2004AnalyzerFullObserverParameters)defaults).getFileName();
151 			if (humanLike_observingEnabled == null) humanLike_observingEnabled = ((UT2004AnalyzerFullObserverParameters)defaults).isHumanLikeObservingEnabled();
152 			if (humanLike_botName == null) humanLike_botName = ((UT2004AnalyzerFullObserverParameters)defaults).getHumanLikeBotName();
153 			if (humanLike_writer == null) humanLike_writer = ((UT2004AnalyzerFullObserverParameters)defaults).getHumanLikeWriter();
154 		}
155 	}
156 
157 	
158 
159 	
160 	
161 }