View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.analyzer.stats;
2   
3   import com.google.inject.Inject;
4   
5   import cz.cuni.amis.pogamut.base.communication.command.IAct;
6   import cz.cuni.amis.pogamut.base.component.bus.IComponentBus;
7   import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
8   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentStats;
9   import cz.cuni.amis.pogamut.ut2004.analyzer.UT2004AnalyzerFullObserver;
10  import cz.cuni.amis.pogamut.ut2004.analyzer.UT2004AnalyzerFullObserverParameters;
11  import cz.cuni.amis.pogamut.ut2004.analyzer.UT2004AnalyzerObserver;
12  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.ConfigurationObserver;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.InitializeObserver;
14  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
15  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.MyInventory;
16  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
17  import cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004WorldView;
18  
19  /**
20   * Observer that provides logging of bot's health, number of deaths, traveled distance and bot's location, etc.
21   * It is directly using {@link AgentStats} for that purpose.
22   */
23  public class UT2004AnalyzerObsStats extends UT2004AnalyzerFullObserver {
24  
25  	private AgentStats stats;
26      
27  	@Inject
28  	public UT2004AnalyzerObsStats(UT2004AnalyzerFullObserverParameters params,
29  			                      IComponentBus bus,         IAgentLogger agentLogger,
30  			                      UT2004WorldView worldView, IAct act) {
31  		super(params, bus, agentLogger, worldView, act);
32  		stats = new AgentStats(this);
33  		stats.setObserver(true);
34  		if (getParams().isWaitForMatchRestart()) {
35  			stats.setLogBeforeMatchRestart(false);
36  		} else {
37  			stats.startOutput(getOutputFilePath(), true);
38  		}
39  	}
40  
41  	/**
42  	 * Returns detailed statistics about the agent.
43  	 * @return
44  	 */
45  	public AgentStats getStats() {
46  		return stats;
47  	}
48  
49  	@Override
50  	protected void gameRestartEnd() {
51  		stats.startOutput(getOutputFilePath(), true);
52  	}
53  	
54  	/**
55  	 * Called from the {@link UT2004AnalyzerObserver#startAgent()} after {@link InitializeObserver} command
56  	 * is sent to configure the observer instance.
57  	 * <p><p>
58  	 * Actually enables {@link Self}, {@link MyInventory} and async messages (i.e., {@link BotKilled}).
59  	 */
60  	protected void configureObserver() {
61  		getAct().act(new ConfigurationObserver().setUpdate(0.25).setAll(true).setSelf(true).setAsync(true).setGame(false).setSee(false).setSpecial(false));		
62  	}
63  	
64  }