// submitter.exe <API key> <input field file> <tag> static void Main(string[] args) { string apiKey = args[0]; string inpFileName = args[1]; string tag = args[2]; var uri = new Uri("https://davar.icfpcontest.org/teams/148/solutions"); var req = HttpWebRequest.Create(uri); req.Method = "POST"; // ICredentials.GetCredential req.Credentials = new NetworkCredential(apiKey, "").GetCredential(uri, "Basic"); // API key //string authInfo = ":" + apiKey; //req.Headers["Authorization"] = "Basic " + authInfo; InputData inp = InputData.FromJson(new System.IO.StreamReader(inpFileName).ReadToEnd()); var outputs = new List<OutputData>(); foreach (int seed in inp.sourceSeeds) { var od = new OutputData { problemId = inp.id, seed = seed, tag = tag, solution = "oooooooooooooooooooooooooooo".ToLower() }; outputs.Add(od); break; } var solutionSerialized = JsonConvert.SerializeObject(outputs); // Console.WriteLine(solutionSerialized); Console.WriteLine(solutionSerialized.Replace("\"", "\\\"")); var oo = new StreamWriter("aa"); oo.WriteLine(solutionSerialized.Replace("\"", "\\\"")); oo.Close(); byte[] solutionBytes = System.Text.Encoding.UTF8.GetBytes(solutionSerialized); req.ContentLength = solutionBytes.Length; req.ContentType = "application/json"; Stream dataStream = req.GetRequestStream(); dataStream.Write(solutionBytes, 0, solutionBytes.Length); dataStream.Close(); try { WebResponse response = req.GetResponse(); Console.WriteLine(((HttpWebResponse)response).StatusDescription); } catch (Exception e) { Console.WriteLine("Exception: {0}", e); } }
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); }