public MatchResult Run(IProject aProject, ISimpleOutput console) { project = (Project)aProject; Init(); project.EngineOptions.ForcedAddresses = forcedArdresses; project.EngineOptions.Random = new Random(0); Check check = Check.Optimistic; #if DEBUG // this loop restarts test with more and more precise check setting to isolate bugs in engine bool res; do { res = true; try { CompareEngines(check); } catch (EngineDifferException e) { check = e.Check; res = false; } } while (!res); #else CompareEngines(check); #endif return(matchTwo); }
public virtual void Dump(ISimpleOutput output, ParserOptions options) { if (options.XmlFormat) { StringWriter sw = new StringWriter(); XmlSerializer serializer = new XmlSerializer(GetType()); serializer.Serialize(sw, this); sw.Close(); output.Write(sw.GetStringBuilder().ToString()); } else { if (options.Header) { output.WriteLine("Program \"" + Name + "\" (length " + Length.ToString() + ") by \"" + Author + "\""); output.WriteLine(""); } if (options.Instructions) { output.WriteLine(" ORG START"); for (int a = 0; a < Instructions.Count; a++) { output.WriteLine(Instructions[a].GetLine(options, a == StartOffset)); } } } output.WriteLine(""); }
public MatchResult EndMatch(ISimpleOutput console) { Wait(); lock (this) { return(engine.EndMatch(console)); } }
private static void PrintVersions(ISimpleOutput console) { string version = ModuleRegister.GetVersionInfo(); string logo = "http://sourceforge.net/projects/nmars\r\n\r\n" + "2007 Published under LGPL http://www.gnu.org/licenses/lgpl.txt\r\n" + "by Pavel Savara ([email protected])\r\n\r\n"; console.WriteLine(logo + version); }
private static void PrintLogo(ISimpleOutput console) { console.WriteLine("nMars.exe " + new Module().Version + " - http://sourceforge.net/projects/nmars"); if (DumpLogoEvent != null) { DumpLogoEvent.Invoke(console); } console.WriteLine(""); }
public MatchResult Run(IProject project, ISimpleOutput console) { StepResult stepResult; BeginMatch(project); do { stepResult = NextStep(); } while (stepResult != StepResult.Finished); return(EndMatch(console)); }
/// <summary> /// Parse warrior files in project parameter considering parser options and rules /// </summary> /// <param name="aProject">files, rules, options</param> /// <param name="aConsole">output console, could be null</param> /// <returns>list of errors</returns> public override ParseResult Parse(IProject aProject, ISimpleOutput aConsole) { //cache and ceck rules if (cachedRules == null) { cachedRules = aProject.Rules; } else if (!cachedRules.Equals(aProject.Rules)) { throw new ParserException("Caching parser can cache only warriors compiled under same rules"); } return(base.Parse(aProject, aConsole)); }
/// <summary> /// Parse warrior files in project parameter considering parser options and rules /// </summary> /// <param name="aProject">files, rules, options</param> /// <param name="aConsole">output console, could be null</param> /// <returns>list of errors</returns> public override ParseResult Parse(IProject aProject, ISimpleOutput aConsole) { //cache and ceck rules if (cachedRules==null) { cachedRules = aProject.Rules; } else if (!cachedRules.Equals(aProject.Rules)) { throw new ParserException("Caching parser can cache only warriors compiled under same rules"); } return base.Parse(aProject, aConsole); }
public override void Dump(ISimpleOutput tw, ParserOptions options) { if (options.XmlFormat) { base.Dump(tw, options); return; } if (options.Header) { tw.WriteLine("Program \"" + Name + "\" (length " + Length.ToString() + ") by \"" + Author + "\""); tw.WriteLine(""); } if (options.Metainfo) { tw.WriteLine(";redcode"); if (Name != null) { tw.WriteLine(";name " + Name); } if (Author != null) { tw.WriteLine(";author " + Author); } if (Date != null) { tw.WriteLine(";date " + Date); } tw.WriteLine(""); } if (options.Instructions) { if (options.Offset) { tw.Write(" "); } if (options.Labels && Length > 0) { tw.WriteLine(" ORG " + this[StartOffset].Label); } else { tw.WriteLine(" ORG START"); } for (int a = 0; a < Instructions.Count; a++) { tw.WriteLine(this[a].GetLine(options, a == StartOffset)); } tw.WriteLine(""); } }
private static void PrintHelp(ISimpleOutput console) { PrintLogo(console); console.WriteLine(""); console.WriteLine("Usage: nMars.exe [options] file1 [files ..]"); console.WriteLine(""); console.WriteLine("General:"); console.WriteLine(" -@ file load options from text file (pMars compatible)"); console.WriteLine(" -@l file load project from xml file"); console.WriteLine(" -@s file save project to xml file, (use .nmproj extension)"); console.WriteLine(" -nP name Change parser component"); console.WriteLine(" -nE name Change engine component"); console.WriteLine(" -v Component versions"); console.WriteLine(""); console.WriteLine("Mode:"); console.WriteLine(" -mm Match mode [default]"); console.WriteLine(" -mt Tournament without self fight mode"); console.WriteLine(" -ms Tournament with self fight mode"); console.WriteLine(" -mf First versus all other mode"); console.WriteLine(""); console.WriteLine("Rules:"); console.WriteLine(" -r # Rounds to play [1]"); console.WriteLine(" -s # Size of core [8000]"); console.WriteLine(" -c # Cycle until tie [80000]"); console.WriteLine(" -p # Max. processes [8000]"); console.WriteLine(" -l # Max. warrior length [100]"); console.WriteLine(" -d # Min. warriors distance"); console.WriteLine(" -S # Size of P-space [500]"); console.WriteLine(" -f # Fixed position series"); console.WriteLine(" -xp Disable P-space"); console.WriteLine(""); console.WriteLine("Dumps:"); console.WriteLine(" -b Brief/silent parser mode"); console.WriteLine(" -bh No header"); console.WriteLine(" -bl No logo"); console.WriteLine(" -bs No status"); console.WriteLine(" -br No match results"); console.WriteLine(" -k Output in KotH format"); console.WriteLine(" -ue .ext Dump warriors to files with extension"); console.WriteLine(" -um Dump format with metainfo [off]"); console.WriteLine(" -uo Dump format with offset [off]"); console.WriteLine(" -ul Dump format with labels [off]"); console.WriteLine(" -up Dump format with expressions [off]"); console.WriteLine(" -uc Dump format with comments [off]"); console.WriteLine(" -ux Dump format xml"); if (DumpHelpEvent != null) { DumpHelpEvent.Invoke(console); } console.WriteLine(""); }
/// <summary> /// Main procedure of commandline user interface /// </summary> public static Project Prepare(string[] args, ComponentLoader components, ISimpleOutput console, out bool interactive, out string saveProjectFile) { bool nologo; saveProjectFile = null; interactive = false; Project project; try { project = ParseArguments(args, out nologo, out interactive, out saveProjectFile, components); } catch (ArgumentException ex) { if (ex.Message == "versions") { PrintVersions(console); } else if (ex.Message == "help") { PrintHelp(console); } else if (ex.Message == "Please provide valid arguments") { PrintHelp(console); console.WriteLine(""); console.ErrorWriteLine(ex.Message); } else { console.ErrorWriteLine(ex.Message); } return(null); } if (project.WarriorFiles.Count == 0) { PrintHelp(console); return(null); } if (!nologo) { PrintLogo(console); } return(project); }
public MatchResult EndMatch(ISimpleOutput console) { FinalizeMatch(); results.ComputePoints(); if (console!=null) { if (Project.EngineOptions.DumpResults) { results.Dump(console, Project); } if (Project.EngineOptions.StatusLine) { console.WriteLine("========== Finished fight of " + Project.Warriors.Count + " warriors =========="); } } return results; }
public MatchResult EndMatch(ISimpleOutput console) { FinalizeMatch(); results.ComputePoints(); if (console != null) { if (Project.EngineOptions.DumpResults) { results.Dump(console, Project); } if (Project.EngineOptions.StatusLine) { console.WriteLine("========== Finished fight of " + Project.Warriors.Count + " warriors =========="); } } return(results); }
public static ParseResult Parse(ComponentLoader components, ISimpleOutput console, Project project) { if (project == null) { return null; } if (components.Parser != null) { return components.Parser.Parse(project, console); } else { console.ErrorWriteLine("Parser not found:" + components.ParserName); return null; } }
public static ParseResult Parse(ComponentLoader components, ISimpleOutput console, Project project) { if (project == null) { return(null); } if (components.Parser != null) { return(components.Parser.Parse(project, console)); } else { console.ErrorWriteLine("Parser not found:" + components.ParserName); return(null); } }
public override void Dump(ISimpleOutput tw, ParserOptions options) { if (options.XmlFormat) { base.Dump(tw, options); return; } if (options.Header) { tw.WriteLine("Program \"" + Name + "\" (length " + Length.ToString() + ") by \"" + Author + "\""); tw.WriteLine(""); } if (options.Metainfo) { tw.WriteLine(";redcode"); if (Name != null) tw.WriteLine(";name " + Name); if (Author != null) tw.WriteLine(";author " + Author); if (Date != null) tw.WriteLine(";date " + Date); tw.WriteLine(""); } if (options.Instructions) { if (options.Offset) { tw.Write(" "); } if (options.Labels && Length > 0) { tw.WriteLine(" ORG " + this[StartOffset].Label); } else { tw.WriteLine(" ORG START"); } for (int a = 0; a < Instructions.Count; a++) { tw.WriteLine(this[a].GetLine(options, a == StartOffset)); } tw.WriteLine(""); } }
/// <summary> /// Parse warrior files in project parameter considering parser options and rules /// </summary> /// <param name="aProject">files, rules, options</param> /// <param name="aConsole">output console, could be null</param> /// <returns>list of errors</returns> public virtual ParseResult Parse(IProject aProject, ISimpleOutput aConsole) { project = aProject; result = new ParseResult(); console = aConsole; project.Warriors.Clear(); int succ = 0; foreach (string file in project.WarriorFiles) { if (project.ParserOptions.StatusLine && console != null) { console.WriteLine("Parsing: " + file); } IWarrior warrior = Parse(file); project.Warriors.Add(warrior); if (warrior != null) { succ++; if (project.ParserOptions.DumpFiles) { StreamWriter sw = new StreamWriter(Path.ChangeExtension(file, project.ParserOptions.DumpExt)); warrior.Dump(new WrappedTextWriter(sw), project.ParserOptions); sw.Close(); } else if (console != null) { warrior.Dump(console, project.ParserOptions); } } else { result.Succesfull = false; } } if (project.ParserOptions.StatusLine && console != null) { console.WriteLine("========== Compiled " + project.WarriorFiles.Count + " warriors, " + (project.WarriorFiles.Count - succ) + " failed =========="); } return(result); }
/// <summary> /// Parse warrior files in project parameter considering parser options and rules /// </summary> /// <param name="aProject">files, rules, options</param> /// <param name="aConsole">output console, could be null</param> /// <returns>list of errors</returns> public virtual ParseResult Parse(IProject aProject, ISimpleOutput aConsole) { project = aProject; result = new ParseResult(); console = aConsole; project.Warriors.Clear(); int succ = 0; foreach (string file in project.WarriorFiles) { if (project.ParserOptions.StatusLine && console != null) { console.WriteLine("Parsing: " + file); } IWarrior warrior = Parse(file); project.Warriors.Add(warrior); if (warrior != null) { succ++; if (project.ParserOptions.DumpFiles) { StreamWriter sw = new StreamWriter(Path.ChangeExtension(file, project.ParserOptions.DumpExt)); warrior.Dump(new WrappedTextWriter(sw), project.ParserOptions); sw.Close(); } else if (console != null) warrior.Dump(console, project.ParserOptions); } else { result.Succesfull = false; } } if (project.ParserOptions.StatusLine && console!=null) { console.WriteLine("========== Compiled " + project.WarriorFiles.Count + " warriors, " + (project.WarriorFiles.Count - succ) + " failed =========="); } return result; }
public void Dump(ISimpleOutput output, IProject project) { IList <ResultsHelper> res = PrepareResults(project, project.EngineOptions.SortResults); if (project.EngineOptions.KOTHFormat) { //TODO throw new NotImplementedException("Sorry, not yet implemented."); } else { for (int w = 0; w < res.Count; w++) { IWarrior warrior = res[w].warrior; output.WriteLine(string.Format("{0} by {1} scores {2}", warrior.Name, warrior.Author, res[w].score)); } if (res.Count == 2) { int idx = res[0].originalIndex; output.WriteLine(string.Format("Results: {0} {1} {2}", wins[idx], looses[idx], ties[idx])); } } }
public MatchResult Run(IProject aProject, ISimpleOutput console) { project = (Project)aProject; Init(); project.EngineOptions.ForcedAddresses = forcedArdresses; project.EngineOptions.Random = new Random(0); Check check = Check.Optimistic; #if DEBUG // this loop restarts test with more and more precise check setting to isolate bugs in engine bool res; do { res = true; try { CompareEngines(check); } catch (EngineDifferException e) { check = e.Check; res = false; } } while (!res); #else CompareEngines(check); #endif return matchTwo; }
public MatchResult Run(IProject aProject, ISimpleOutput console) { BeginMatch(aProject); while (NextStep() != StepResult.Finished) { } return EndMatch(console); }
public MatchResult EndMatch(ISimpleOutput console) { pMarsDll.pMarsEndMatch(); dllCore = IntPtr.Zero; dllCoreSize = 0; dllCyclesLeft = IntPtr.Zero; dllRound = IntPtr.Zero; dllWarriors = IntPtr.Zero; dllWarriorsCout = 0; dllWarrirorsLeft = IntPtr.Zero; dllNextWarrior = IntPtr.Zero; dllTasksStart = IntPtr.Zero; dllTasksEnd = IntPtr.Zero; dllPSpaces = IntPtr.Zero; dllCoreLoaded = false; dllTasksLoaded = false; dllWarriorsLoaded = false; dllDataLinked = false; lastInstruction = null; try { File.Delete(errFile); } catch (Exception) { // swallow } //results.ComputePoints(); //results.Dump(output, Project); return results; }
private static void PrintLogo(ISimpleOutput console) { console.WriteLine("nMars.exe " + new Module().Version + " - http://sourceforge.net/projects/nmars"); if (DumpLogoEvent != null) DumpLogoEvent.Invoke(console); console.WriteLine(""); }
private static void PrintVersions(ISimpleOutput console) { string version = ModuleRegister.GetVersionInfo(); string logo = "http://sourceforge.net/projects/nmars\r\n\r\n" + "2007 Published under LGPL http://www.gnu.org/licenses/lgpl.txt\r\n" + "by Pavel Savara ([email protected])\r\n\r\n"; console.WriteLine(logo + version); }
public static void Run(ComponentLoader components, ISimpleOutput console, Project project) { if (project.Rules.Rounds > 0) { if (components.Engine != null) { switch (project.EngineOptions.EngineMode) { case EngineMode.Match: components.Engine.Run(project, console); break; case EngineMode.TournamentNoSelf: case EngineMode.TournamentWithSelf: if (project.Warriors.Count < 2) { console.ErrorWriteLine("Tournament mode could be run only with two or more warriors"); return; } for (int wa = 0; wa < project.Warriors.Count; wa++) { int st = wa; if (project.EngineOptions.EngineMode == EngineMode.TournamentNoSelf) { st++; } for (int wb = st; wb < project.Warriors.Count; wb++) { Project p = new Project(project.Rules); p.EngineOptions = new EngineOptions(project.EngineOptions); p.EngineOptions.EngineMode = EngineMode.Match; p.Warriors.Add(project.Warriors[wa]); p.Warriors.Add(project.Warriors[wb]); components.Engine.Run(p, console); } } break; case EngineMode.FirstVersusOthers: if (project.Warriors.Count < 2) { console.ErrorWriteLine("First versus others mode could be run only with two or more warriors"); return; } for (int wa = 1; wa < project.Warriors.Count; wa++) { Project p = new Project(project.Rules); p.EngineOptions = project.EngineOptions; p.EngineOptions.EngineMode = EngineMode.Match; p.Warriors.Add(project.Warriors[0]); p.Warriors.Add(project.Warriors[wa]); components.Engine.Run(p, console); } break; default: throw new ArgumentException("Unknown engine mode"); } } else { console.ErrorWriteLine("Engine not found:" + components.EngineName); } } }
public static void Run(ComponentLoader components, ISimpleOutput console, Project project) { if (project.Rules.Rounds > 0) { if (components.Engine != null) { switch (project.EngineOptions.EngineMode) { case EngineMode.Match: components.Engine.Run(project, console); break; case EngineMode.TournamentNoSelf: case EngineMode.TournamentWithSelf: if (project.Warriors.Count < 2) { console.ErrorWriteLine("Tournament mode could be run only with two or more warriors"); return; } for (int wa = 0; wa < project.Warriors.Count; wa++) { int st = wa; if (project.EngineOptions.EngineMode == EngineMode.TournamentNoSelf) st++; for (int wb = st; wb < project.Warriors.Count; wb++) { Project p = new Project(project.Rules); p.EngineOptions = new EngineOptions(project.EngineOptions); p.EngineOptions.EngineMode = EngineMode.Match; p.Warriors.Add(project.Warriors[wa]); p.Warriors.Add(project.Warriors[wb]); components.Engine.Run(p, console); } } break; case EngineMode.FirstVersusOthers: if (project.Warriors.Count < 2) { console.ErrorWriteLine("First versus others mode could be run only with two or more warriors"); return; } for (int wa = 1; wa < project.Warriors.Count; wa++) { Project p = new Project(project.Rules); p.EngineOptions = project.EngineOptions; p.EngineOptions.EngineMode = EngineMode.Match; p.Warriors.Add(project.Warriors[0]); p.Warriors.Add(project.Warriors[wa]); components.Engine.Run(p, console); } break; default: throw new ArgumentException("Unknown engine mode"); } } else { console.ErrorWriteLine("Engine not found:" + components.EngineName); } } }
public void Dump(ISimpleOutput tw) { SourceWarrior.Dump(tw); }
public void Dump(ISimpleOutput output, IProject project) { IList<ResultsHelper> res = PrepareResults(project, project.EngineOptions.SortResults); if (project.EngineOptions.KOTHFormat) { //TODO throw new NotImplementedException("Sorry, not yet implemented."); } else { for (int w = 0; w < res.Count; w++) { IWarrior warrior = res[w].warrior; output.WriteLine(string.Format("{0} by {1} scores {2}", warrior.Name, warrior.Author, res[w].score)); } if (res.Count == 2) { int idx = res[0].originalIndex; output.WriteLine(string.Format("Results: {0} {1} {2}", wins[idx], looses[idx], ties[idx])); } } }
public void Dump(ISimpleOutput tw, ParserOptions options) { SourceWarrior.Dump(tw, options); }
public MatchResult Run(IProject project, ISimpleOutput console) { BeginMatch(project); Continue(false); return(EndMatch(console)); }
public virtual void Dump(ISimpleOutput output, ParserOptions options) { if (options.XmlFormat) { StringWriter sw=new StringWriter(); XmlSerializer serializer = new XmlSerializer(GetType()); serializer.Serialize(sw, this); sw.Close(); output.Write(sw.GetStringBuilder().ToString()); } else { if (options.Header) { output.WriteLine("Program \"" + Name + "\" (length " + Length.ToString() + ") by \"" + Author + "\""); output.WriteLine(""); } if (options.Instructions) { output.WriteLine(" ORG START"); for (int a = 0; a < Instructions.Count; a++) { output.WriteLine(Instructions[a].GetLine(options, a == StartOffset)); } } } output.WriteLine(""); }
public void Dump(ISimpleOutput output) { Dump(output, ParserOptions.Default); }
private static void PrintHelp(ISimpleOutput console) { PrintLogo(console); console.WriteLine(""); console.WriteLine("Usage: nMars.exe [options] file1 [files ..]"); console.WriteLine(""); console.WriteLine("General:"); console.WriteLine(" -@ file load options from text file (pMars compatible)"); console.WriteLine(" -@l file load project from xml file"); console.WriteLine(" -@s file save project to xml file, (use .nmproj extension)"); console.WriteLine(" -nP name Change parser component"); console.WriteLine(" -nE name Change engine component"); console.WriteLine(" -v Component versions"); console.WriteLine(""); console.WriteLine("Mode:"); console.WriteLine(" -mm Match mode [default]"); console.WriteLine(" -mt Tournament without self fight mode"); console.WriteLine(" -ms Tournament with self fight mode"); console.WriteLine(" -mf First versus all other mode"); console.WriteLine(""); console.WriteLine("Rules:"); console.WriteLine(" -r # Rounds to play [1]"); console.WriteLine(" -s # Size of core [8000]"); console.WriteLine(" -c # Cycle until tie [80000]"); console.WriteLine(" -p # Max. processes [8000]"); console.WriteLine(" -l # Max. warrior length [100]"); console.WriteLine(" -d # Min. warriors distance"); console.WriteLine(" -S # Size of P-space [500]"); console.WriteLine(" -f # Fixed position series"); console.WriteLine(" -xp Disable P-space"); console.WriteLine(""); console.WriteLine("Dumps:"); console.WriteLine(" -b Brief/silent parser mode"); console.WriteLine(" -bh No header"); console.WriteLine(" -bl No logo"); console.WriteLine(" -bs No status"); console.WriteLine(" -br No match results"); console.WriteLine(" -k Output in KotH format"); console.WriteLine(" -ue .ext Dump warriors to files with extension"); console.WriteLine(" -um Dump format with metainfo [off]"); console.WriteLine(" -uo Dump format with offset [off]"); console.WriteLine(" -ul Dump format with labels [off]"); console.WriteLine(" -up Dump format with expressions [off]"); console.WriteLine(" -uc Dump format with comments [off]"); console.WriteLine(" -ux Dump format xml"); if (DumpHelpEvent != null) DumpHelpEvent.Invoke(console); console.WriteLine(""); }
public void Dump(ISimpleOutput output) { Dump(output, ParserOptions.Default); }
public MatchResult Run(IProject project, ISimpleOutput console) { StepResult stepResult; BeginMatch(project); do { stepResult = NextStep(); } while (stepResult != StepResult.Finished); return EndMatch(console); }
static void OnDumpHelpEvent(ISimpleOutput console) { console.WriteLine(""); console.WriteLine("Debugger:"); console.WriteLine(" -e Interactive debugger mode"); }
/// <summary> /// Main procedure of commandline user interface /// </summary> public static Project Prepare(string[] args, ComponentLoader components, ISimpleOutput console, out bool interactive, out string saveProjectFile) { bool nologo; saveProjectFile=null; interactive=false; Project project; try { project = ParseArguments(args, out nologo, out interactive, out saveProjectFile, components); } catch(ArgumentException ex) { if (ex.Message == "versions") { PrintVersions(console); } else if (ex.Message == "help") { PrintHelp(console); } else if (ex.Message == "Please provide valid arguments") { PrintHelp(console); console.WriteLine(""); console.ErrorWriteLine(ex.Message); } else { console.ErrorWriteLine(ex.Message); } return null; } if (project.WarriorFiles.Count == 0) { PrintHelp(console); return null; } if (!nologo) PrintLogo(console); return project; }