public bool HasChanges(OsianLogic logic) { var nb = new[] { logic.Players[0].Cost, logic.Players[1].Cost, logic.Players[0].Base, logic.Players[1].Base }; if (!nb.SequenceEqual(_basics)) { return(true); } foreach (var item in _trackedStart) { if (_trackedEnd[item.Key].ToString() != _trackedStart[item.Key].ToString()) { return(true); } } return(false); }
private void _record(OsianLogic logic, SortedDictionary <string, RecordData> put, bool attackFrame = false) { var left = logic.Players[0]; var data = logic.Map; for (int i = 0; i < OsianLogic.LEN_X; i++) { for (int j = 0; j < OsianLogic.LEN_Y; j++) { if (data.Map[i, j] is BarrackMapObject b) { put.Add("a" + i + "," + j, RecordData.Make(i, j, 1, b.Owner == left ? 0 : 1, "team" + (b.Owner == left ? "l" : (b.Owner == null ? "n" : "r")), "")); } if (data.Map[i, j] is ObstacleMapObject ob) { put.Add("a" + i + "," + j, RecordData.Make(i, j, 1, ob.Owner == left ? 0 : 1, "obstacle", "")); } } } Dictionary <string, string> dup = new Dictionary <string, string> (); foreach (var army in data.Army) { var keystr = _armyStr(army, ""); keystr = ((int)('e' - keystr[0])) + keystr; var key = "m" + army.Timestamp + "." + keystr; var dupkey = keystr + army.PosX + "," + army.PosY; if (dup.ContainsKey(dupkey)) { var v = put[dup[dupkey]]; v.c = "x" + (int.Parse(v.c.Substring(1)) + 1); put[dup[dupkey]] = v; } else { var atk = attackFrame; var rd = RecordData.Make(army.PosX, army.PosY - (atk ? 0.02f : 0.0f), 1, army.Owner == left ? 0 : 1, _armyStr(army, atk ? "a" : ""), "x1"); put.Add(key, rd); dup.Add(dupkey, key); } } }
static void Main(string[] args) { using (var binresult = File.Create("Results.bin")) using (var rwriter = new BinaryWriter(binresult)) if (args.Length <= 1) { Console.WriteLine("Osian Judger Program."); Console.WriteLine("Usage:"); Console.WriteLine("<this program> <compiler> <folder of sources>"); } else { MatchCompiler.COMPILER_COMMAND = args[0]; var listDir = Directory.GetDirectories(args[1]); for (int i = 0; i < listDir.Length; i++) { _compile(listDir[i], rwriter); } using (var stream = File.CreateText("Results.txt")) { for (int i = 0; i < listDir.Length; i++) { int wins = 0; int matches = 0; if (!_compiledFiles.ContainsKey(listDir[i])) { continue; } for (int j = 0; j < listDir.Length; j++) { if (i == j) { continue; } if (!_compiledFiles.ContainsKey(listDir[j])) { continue; } var exe1 = _compiledFiles[listDir[i]]; var exe2 = _compiledFiles[listDir[j]]; ResetMaps(); for (int m = 0; m < _maps.Count; m++) { matches++; Game.Replay.ReplayOrganizer org = new Game.Replay.ReplayOrganizer(); using (var judger = new OsianLogic( _maps[m], org, new MatchOperationProvider(exe1), new MatchOperationProvider(exe2) )) { switch (judger.Run()) { case 0: wins++; org.WriteReplay(string.Format("{0}-{1}-map{2}-win-{3}.html", Path.GetFileNameWithoutExtension(listDir[i]), Path.GetFileNameWithoutExtension(listDir[j]), m, DateTime.Now.Ticks)); stream.WriteLine(string.Format("{0} wins {1} on map {2}.", Path.GetFileNameWithoutExtension(listDir[i]), Path.GetFileNameWithoutExtension(listDir[j]), m)); break; case 1: org.WriteReplay(string.Format("{0}-{1}-map{2}-lose-{3}.html", Path.GetFileNameWithoutExtension(listDir[i]), Path.GetFileNameWithoutExtension(listDir[j]), m, DateTime.Now.Ticks)); stream.WriteLine(string.Format("{0} loses in the game with {1} on map {2}.", Path.GetFileNameWithoutExtension(listDir[i]), Path.GetFileNameWithoutExtension(listDir[j]), m)); break; case -1: org.WriteReplay(string.Format("{0}-{1}-map{2}-tie-{3}.html", Path.GetFileNameWithoutExtension(listDir[i]), Path.GetFileNameWithoutExtension(listDir[j]), m, DateTime.Now.Ticks)); stream.WriteLine(string.Format("{0} ties in the game with {1} on map {2}.", Path.GetFileNameWithoutExtension(listDir[i]), Path.GetFileNameWithoutExtension(listDir[j]), m)); break; } } } } rwriter.Write(1); rwriter.Write(Path.GetFileNameWithoutExtension(listDir[i])); rwriter.Write(wins); rwriter.Write(matches); rwriter.Write(matches > 0 ? wins * 100.0 / matches : 0.0); _results.Add(Path.GetFileNameWithoutExtension(listDir[i]), string.Format("{0} wins in {1} matches, rate {2}%.", wins, matches, matches > 0 ? wins * 100 / matches : 0)); } foreach (var kv in _results) { stream.WriteLine(kv.Key + " - " + kv.Value); } rwriter.Write(0); } foreach (var item in _compiledFiles.Values) { File.Delete(item); } } }
public void RecordEndFrame(OsianLogic logic) { _record(logic, _trackedEnd); MakeConsistent(); }
public void RecordStartFrame(OsianLogic logic, bool attackFrame = false) { _basics = new[] { logic.Players[0].Cost, logic.Players[1].Cost, logic.Players[0].Base, logic.Players[1].Base }; _record(logic, _trackedStart, attackFrame); }
public void Bind(OsianLogic logic) { BoundLogic = logic; }