public GameData(InputData inputData, ArgParser argParser) { InputData = inputData; Units = inputData.units.Select(inputUnit => new Unit(inputUnit)).ToArray(); var phrases = new List<PowerPhraseInfo>(); phrases.Add(new PowerPhraseInfo("", -1)); phrases.AddRange(argParser.PowerPhrases.Select((t, i) => new PowerPhraseInfo(t, i))); PowerPhraseData = new PowerPhraseData(phrases.ToArray(), argParser.PhraseMetricType); }
static void Main(string[] args) { var argParser = new ArgParser(args); var outputDatas = new List<OutputData>(); int timeLimit = (argParser.TimeLimit > 0 ? argParser.TimeLimit : 10000000); DateTime criticalTime = DateTime.Now + new TimeSpan(0, 0, timeLimit); foreach (var fileName in argParser.InputFileNames) { DebugPrinter.WriteLine("Processing {0}", fileName); DebugPrinter.WriteTrace("Processing {0}", fileName); var f = new StreamReader(fileName); var s = f.ReadToEnd(); var inputData = JsonConvert.DeserializeObject<InputData>(s); var gameData = new GameData(inputData, argParser); DebugPrinter.WriteLine(PrettyPrinter.PrettyPrint(gameData.InputData)); DateTime startTime = DateTime.Now; for (int seedIdx = 0; seedIdx < gameData.InputData.sourceSeeds.Length; ++seedIdx) { int seed = gameData.InputData.sourceSeeds[seedIdx]; DebugPrinter.WriteTrace(" seed #{0}/{1}: {2}", seedIdx + 1, gameData.InputData.sourceSeeds.Length, seed); string moves = new Algo2(gameData).Run(seed).String; var outputData = new OutputData { problemId = inputData.id, seed = seed, solution = moves, }; outputDatas.Add(outputData); gameData.Reset(); DateTime now = DateTime.Now; int avgTimeMs = (int)((now - startTime).TotalMilliseconds / (seedIdx + 1)); if (now + new TimeSpan(0, 0, 0, 0, avgTimeMs) > criticalTime) { DebugPrinter.WriteLine("Break due to time limit"); break; } } } string outputStr = JsonConvert.SerializeObject(outputDatas); DebugPrinter.WriteLine("{0}", outputStr.Replace("\"", "\\\"")); Console.WriteLine(outputStr); }