1 package cz.cuni.amis.pogamut.ut2004.analyzer;
2
3 import java.io.File;
4
5 import com.google.inject.Inject;
6
7 import cz.cuni.amis.pogamut.base.communication.command.IAct;
8 import cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEventListener;
9 import cz.cuni.amis.pogamut.base.component.bus.IComponentBus;
10 import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
11 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
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.GameRestarted;
16 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.MyInventory;
17 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
18 import cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004WorldView;
19 import cz.cuni.amis.pogamut.ut2004.observer.impl.UT2004Observer;
20 import cz.cuni.amis.utils.exception.PogamutException;
21
22
23
24
25
26
27
28
29
30 @Deprecated
31 public class UT2004AnalyzerObserver extends UT2004Observer implements IUT2004AnalyzerObserver {
32
33 private UnrealId observedBotId;
34
35 private IWorldEventListener<GameRestarted> gameRestartedListener = new IWorldEventListener<GameRestarted>() {
36
37 @Override
38 public void notify(GameRestarted event) {
39 if (event.isStarted()) {
40 gameRestartStarted();
41 } else
42 if (event.isFinished()) {
43 gameRestartEnd();
44 } else {
45 throw new PogamutException("GameRestarted has started==false && finished==false as well, invalid!", this);
46 }
47 }
48
49 };
50
51 @Inject
52 public UT2004AnalyzerObserver(UT2004AnalyzerObserverParameters params,
53 IComponentBus bus, IAgentLogger agentLogger,
54 UT2004WorldView worldView, IAct act) {
55 super(params, bus, agentLogger, worldView, act);
56 observedBotId = UnrealId.get(params.getObservedAgentId());
57 getWorldView().addEventListener(GameRestarted.class, gameRestartedListener);
58 }
59
60 @Override
61 public UT2004AnalyzerObserverParameters getParams() {
62 return (UT2004AnalyzerObserverParameters) super.getParams();
63 }
64
65 @Override
66 public UnrealId getObservedBotId() {
67 return observedBotId;
68 }
69
70
71
72
73
74 public String getOutputFilePath() {
75 String path = getParams().getOutputPath();
76 if (path == null) path = ".";
77 path += File.separator;
78 if (getParams().getFileName() != null) {
79 path += getParams().getFileName();
80 } else {
81 path += getObservedBotId().toString();
82 path += ".csv";
83 }
84 return path;
85 }
86
87
88
89
90
91
92
93
94
95 protected void gameRestartStarted() {
96 }
97
98
99
100
101
102
103
104
105
106 protected void gameRestartEnd() {
107 }
108
109
110
111
112
113 @Override
114 protected void startAgent() {
115 super.startAgent();
116 getAct().act(new InitializeObserver().setId(getParams().getObservedAgentId()));
117 configureObserver();
118 }
119
120 @Override
121 protected void startPausedAgent() {
122 super.startPausedAgent();
123 getAct().act(new InitializeObserver().setId(getParams().getObservedAgentId()));
124 configureObserver();
125 }
126
127
128
129
130
131
132
133 protected void configureObserver() {
134 getAct().act(new ConfigurationObserver().setUpdate(0.2).setAll(true).setSelf(true).setAsync(true).setGame(false).setSee(false).setSpecial(false));
135 }
136
137 }