@@ -48,8 +48,11 @@ public static bool Validate(MatchConfigurationT config, bool surpressWarnings =
4848 config . PlayerConfigurations ??= new ( ) ;
4949 config . ScriptConfigurations ??= new ( ) ;
5050
51- valid = ValidatePlayers ( ctx , config . PlayerConfigurations , surpressWarnings ) && valid ;
52- valid = ValidateScripts ( ctx , config . ScriptConfigurations ) && valid ;
51+ Dictionary < string , ( string rootDir , string runCmd ) > agentIdTracker = new ( ) ;
52+ valid =
53+ ValidatePlayers ( ctx , config . PlayerConfigurations , agentIdTracker , surpressWarnings )
54+ && valid ;
55+ valid = ValidateScripts ( ctx , config . ScriptConfigurations , agentIdTracker ) && valid ;
5356
5457 Logger . LogDebug ( valid ? "Match config is valid." : "Match config is invalid!" ) ;
5558 return valid ;
@@ -58,16 +61,14 @@ public static bool Validate(MatchConfigurationT config, bool surpressWarnings =
5861 private static bool ValidatePlayers (
5962 ConfigContextTracker ctx ,
6063 List < PlayerConfigurationT > players ,
64+ Dictionary < string , ( string rootDir , string runCmd ) > agentIdTracker ,
6165 bool surpressWarnings
6266 )
6367 {
6468 bool valid = true ;
6569 int humanCount = 0 ;
6670 int humanIndex = - 1 ;
6771
68- // map of agentid -> rootdir,runcmd
69- Dictionary < string , ( string rootDir , string runCmd ) > agentIdTracker = new ( ) ;
70-
7172 for ( int i = 0 ; i < players . Count ; i ++ )
7273 {
7374 using var _ = ctx . Begin ( $ "{ Fields . CarsList } [{ i } ]") ;
@@ -212,11 +213,11 @@ bool surpressWarnings
212213
213214 private static bool ValidateScripts (
214215 ConfigContextTracker ctx ,
215- List < ScriptConfigurationT > scripts
216+ List < ScriptConfigurationT > scripts ,
217+ Dictionary < string , ( string rootDir , string runCmd ) > agentIdTracker
216218 )
217219 {
218220 bool valid = true ;
219- HashSet < string > agentIds = new ( ) ;
220221
221222 for ( int i = 0 ; i < scripts . Count ; i ++ )
222223 {
@@ -238,14 +239,16 @@ List<ScriptConfigurationT> scripts
238239 script . RootDir ??= "" ;
239240 script . ScriptId = $ "{ script . AgentId } /{ Team . Scripts } /{ i } ". GetHashCode ( ) ;
240241
241- // Scripts must have unique agent ids
242- if ( ! agentIds . Add ( script . AgentId ) )
242+ if ( agentIdTracker . TryGetValue ( script . AgentId , out var existing ) )
243243 {
244244 Logger . LogError (
245245 $ "{ ctx . ToStringWithEnd ( Fields . AgentAgentId ) } \" { script . AgentId } \" is already in use. "
246246 + "Each script must have a unique agent ID."
247247 ) ;
248- valid = false ;
248+ }
249+ else
250+ {
251+ agentIdTracker [ script . AgentId ] = ( script . RootDir , script . RunCommand ) ;
249252 }
250253 }
251254
0 commit comments