@@ -51,23 +51,25 @@ const (
5151 TIME_BEFORE_FORCE_QUIT = 5 * time .Second
5252)
5353
54- func TrainAction (
55- tps int ,
56- host string ,
57- vizport int ,
58- vizhost string ,
59- nobrowser bool ,
60- recordFile string ,
61- agentimages []string ,
62- isDebug bool ,
63- isQuiet bool ,
64- mapName string ,
65- shouldProfile ,
66- dumpRaw bool ,
67- durationSeconds int ,
68- ) (bool , error ) {
69-
70- if shouldProfile {
54+ type TrainActionArguments struct {
55+ Tps int
56+ Host string
57+ Vizport int
58+ Vizhost string
59+ Nobrowser bool
60+ RecordFile string
61+ Agentimages []string
62+ IsDebug bool
63+ IsQuiet bool
64+ MapName string
65+ ShouldProfile bool
66+ DumpRaw bool
67+ DurationSeconds int
68+ }
69+
70+ func TrainAction (args TrainActionArguments ) (bool , error ) {
71+
72+ if args .ShouldProfile {
7173 f , err := os .Create ("./cpu.prof" )
7274 if err != nil {
7375 log .Fatal ("could not create CPU profile: " , err )
@@ -80,27 +82,27 @@ func TrainAction(
8082
8183 var gameDuration * time.Duration
8284
83- if durationSeconds > 0 {
84- d := time .Duration (durationSeconds ) * time .Second
85+ if args . DurationSeconds > 0 {
86+ d := time .Duration (args . DurationSeconds ) * time .Second
8587 gameDuration = & d
8688 }
8789
8890 shutdownChan := make (chan bool )
8991 debug := func (str string ) {}
9092
91- if isDebug {
93+ if args . IsDebug {
9294 debug = func (str string ) {
9395 fmt .Printf (DebugColor ("[debug] %s\n " ), str )
9496 }
9597 }
9698
97- if host == "" {
99+ if args . Host == "" {
98100 ip , err := utils .GetCurrentIP ()
99101 utils .Check (err , "Could not determine host IP; you can specify using the `--host` flag." )
100- host = ip
102+ args . Host = ip
101103 }
102104
103- if len (agentimages ) == 0 {
105+ if len (args . Agentimages ) == 0 {
104106 return SHOW_USAGE , bettererrors .New ("No agents were specified" )
105107 }
106108
@@ -110,24 +112,24 @@ func TrainAction(
110112 brokerclient , err := NewMemoryMessageClient ()
111113 utils .Check (err , "ERROR: Could not connect to messagebroker" )
112114
113- mappack , errMappack := mappack .UnzipAndGetHandles (mapcmd .GetMapLocation (mapName ))
115+ mappack , errMappack := mappack .UnzipAndGetHandles (mapcmd .GetMapLocation (args . MapName ))
114116 if errMappack != nil {
115117 utils .FailWith (errMappack )
116118 }
117119
118- gamedescription , err := NewMockGame (tps , mappack )
120+ gamedescription , err := NewMockGame (args . Tps , mappack )
119121 if err != nil {
120122 utils .FailWith (err )
121123 }
122124
123125 game := deathmatch .NewDeathmatchGame (gamedescription )
124126
125- orchestrator := container .MakeLocalContainerOrchestrator (host )
127+ orchestrator := container .MakeLocalContainerOrchestrator (args . Host )
126128
127129 arenaServerUUID := ""
128130
129131 srv := arenaserver .NewServer (
130- host ,
132+ args . Host ,
131133 orchestrator ,
132134 gamedescription ,
133135 game ,
@@ -136,7 +138,7 @@ func TrainAction(
136138 gameDuration ,
137139 )
138140
139- for _ , dockerImageName := range agentimages {
141+ for _ , dockerImageName := range args . Agentimages {
140142 agentManifest , err := types .GetAgentManifestByDockerImageName (dockerImageName , orchestrator )
141143 if err != nil {
142144 return DONT_SHOW_USAGE , err
@@ -157,15 +159,15 @@ func TrainAction(
157159
158160 switch t := msg .(type ) {
159161 case arenaserver.EventStatusGameUpdate :
160- if ! isQuiet {
162+ if ! args . IsQuiet {
161163 fmt .Printf (GameColor ("[game] %s\n " ), t .Status )
162164 }
163165
164166 case arenaserver.EventAgentLog :
165167 fmt .Printf (AgentColor ("[agent] %s\n " ), t .Value )
166168
167169 case arenaserver.EventLog :
168- if ! isQuiet {
170+ if ! args . IsQuiet {
169171 fmt .Printf (LogColor ("[log] %s\n " ), t .Value )
170172 }
171173
@@ -182,7 +184,7 @@ func TrainAction(
182184 fmt .Printf (HeadsUpColor ("[headsup] %s\n " ), t .Value )
183185
184186 case arenaserver.EventRawComm :
185- if dumpRaw {
187+ if args . DumpRaw {
186188 fmt .Printf (AgentColor ("[agent] %s\n " ), t .Value )
187189 }
188190
@@ -211,8 +213,8 @@ func TrainAction(
211213 go common .StreamState (srv , brokerclient , "trainer" )
212214
213215 var recorder recording.RecorderInterface = recording .MakeEmptyRecorder ()
214- if recordFile != "" {
215- recorder = recording .MakeSingleArenaRecorder (recordFile )
216+ if args . RecordFile != "" {
217+ recorder = recording .MakeSingleArenaRecorder (args . RecordFile )
216218 }
217219
218220 recorder .RecordMetadata (gamedescription .GetId (), gamedescription .GetMapContainer ())
@@ -230,8 +232,8 @@ func TrainAction(
230232 vizgames [0 ] = viztypes .NewVizGame (game , gamedescription )
231233
232234 vizservice := visualization .NewVizService (
233- vizhost + ":" + strconv .Itoa (vizport ),
234- mapName ,
235+ args . Vizhost + ":" + strconv .Itoa (args . Vizport ),
236+ args . MapName ,
235237 func () ([]* viztypes.VizGame , error ) { return vizgames , nil },
236238 recorder ,
237239 mappack ,
@@ -245,9 +247,9 @@ func TrainAction(
245247 utils .FailWith (startErr )
246248 }
247249
248- url := "http://" + vizhost + ":" + strconv .Itoa (vizport ) + "/arena/1"
250+ url := "http://" + args . Vizhost + ":" + strconv .Itoa (args . Vizport ) + "/arena/1"
249251
250- if ! nobrowser {
252+ if ! args . Nobrowser {
251253 open .Run (url )
252254 }
253255
0 commit comments