using Cryville.Common; using Cryville.Common.Pdt; using Cryville.Crtr.Event; using System.Collections.Generic; namespace Cryville.Crtr { public class Judge { readonly PdtRuleset _rs; readonly Dictionary ct = new Dictionary(); readonly Dictionary> evs = new Dictionary>(); struct JudgeEvent { public float EndTime; public JudgeDefinition Definition { get; set; } public ContainerState State { get; set; } } public Judge(PdtRuleset rs) { _rs = rs; foreach (var s in rs.scores) { var name = s.Key.Key; scoreDefs.Add(name, s.Value); scores.Add(name, s.Value.init); } } public void Prepare(float time, Identifier input, JudgeDefinition def, ContainerState container) { Dictionary list; if (!evs.TryGetValue(input, out list)) { ct.Add(input, 0); evs.Add(input, list = new Dictionary()); } list.Add(time + def.clip[0], new JudgeEvent { EndTime = time + def.clip[1], Definition = def, State = container }); } public void Feed(string target, float ft, float tt) { Logger.Log("main", 0, "Judge", "Feed {0}: {1}->{2}", target, ft, tt); } public void Cleanup(string target, float ft, float tt) { Logger.Log("main", 0, "Judge", "Cleanup {0}: {1}->{2}", target, ft, tt); } public readonly Dictionary scoreDefs = new Dictionary(); public readonly Dictionary scores = new Dictionary(); readonly Dictionary ScoreCache = new Dictionary(); readonly object _lock = new object(); public Dictionary GetFormattedScoreStrings() { lock (_lock) { if (ScoreCache.Count == 0) { foreach (var s in scores) ScoreCache.Add(s.Key, s.Value.ToString(scoreDefs[s.Key].format)); } return ScoreCache; } } public string GetFullFormattedScoreString() { bool flag = false; string result = ""; foreach (var s in GetFormattedScoreStrings()) { result += string.Format(flag ? "\n{0}: {1}" : "{0}: {1}", IdentifierManager.SharedInstance.Retrieve(s.Key), s.Value); flag = true; } return result; } } public class InputDefinition { public int dim; public bool notnull; public Dictionary pass; } public class JudgeDefinition { public float[] clip; public PdtExpression input; public PdtExpression hit; public Identifier[] pass; public Identifier miss; public Dictionary scores; } public class ScoreOperation { public Identifier name; public Identifier op; public override string ToString() { if (op == default(Identifier)) return name.ToString(); else return string.Format("{0} {1}", name, op); } } public class ScoreDefinition { public PdtExpression value; public float init = 0; public string format = ""; } }