protected bool _LoadMatrix(MemFile memFile, PatternCollection patternCollection) { try { int lMatrixSize = Convert.ToInt32(memFile.ReadLine()); DFANodes = new List <DFANode>(lMatrixSize); for (int i = 1; i < lMatrixSize; i++) { // Console.Error.Write(memFile.LineNbr.ToString() + " - " + i.ToString() + " - "+lMatrixSize.ToString()); DFANode lDFANode = new DFANode(); for (int z = 0; z < 4; z++) { lDFANode[z] = Convert.ToInt32(memFile.ReadPart('\t').Trim()); } int lNodePatterns = Convert.ToInt32(memFile.ReadPart('\t').Trim()); if (lNodePatterns > 0) { lDFANode.Attributes = new List <PatternKey>(lNodePatterns); } for (int p = 0; p < lNodePatterns; p++) { int lPatternTransformation = Convert.ToInt32(memFile.ReadPart(':').Trim()); string lPatternKey = memFile.ReadPart('\t').Trim(); int lTransformation = Convert.ToInt32(memFile.ReadPart('\t').Trim()); Pattern lPattern = patternCollection.FindByKey(lPatternKey); lDFANode.Add(new PatternKey(lPattern, lTransformation)); } memFile.ReadLine(); DFANodes.Add(lDFANode); } } catch (Exception e) { return(SetErrorMessage("Matrix Error - Line # " + memFile.LineNbr.ToString() + ":", e)); } return(false); }
public static int ConsoleGTP(MemFile file, bool loadSilent) { GoBoard lGoBoard = new GoBoard(9); GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard); GTPCommConsole lGTPCommConsole = new GTPCommConsole(); GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommConsole); lGTPCommConsole.Silent = loadSilent; if (file != null) { while (!file.EOF) { string lLine = file.ReadLine(); Console.Error.WriteLine(lLine.Trim('\n')); lGTPCommConsole.SendToEngine(lLine + '\n'); } } lGTPCommConsole.Silent = false; lGTPCommConsole.Listen(); return(0); }
public static int ConsoleGTP(MemFile file, bool loadSilent) { GoBoard lGoBoard = new GoBoard(9); GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard); GTPCommConsole lGTPCommConsole = new GTPCommConsole(); GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommConsole); lGTPCommConsole.Silent = loadSilent; if (file != null) while (!file.EOF) { string lLine = file.ReadLine(); Console.Error.WriteLine(lLine.Trim('\n')); lGTPCommConsole.SendToEngine(lLine + '\n'); } lGTPCommConsole.Silent = false; lGTPCommConsole.Listen(); return 0; }
public bool Load(MemFile memFile, bool continueOnError) { ClearErrorMessages(); StringBuilder lBuffer = new StringBuilder(); bool pStarted = false; int lLineNbr = 0; while (!memFile.EOF) { string lLine = memFile.ReadLine('\n'); if (lLine.Trim().ToUpper() == "###MATRIX") return IsError(); if (lLine.Length > 0) { if (memFile.EOF) lBuffer.Append(lLine); if ((lLine[0] == 'P') || memFile.EOF) { if (pStarted) { // EOF of a Pattern Pattern lPattern = new Pattern(lBuffer.ToString(), lLineNbr); if (lPattern.IsOk()) Add(lPattern); else { SetErrorMessage("ERROR: Unable to compile pattern - Line # " + lLineNbr.ToString() + ":", lPattern); Console.Error.WriteLine("ERROR: Unable to compile pattern."); Console.Error.WriteLine(lPattern.GetErrorMessage()); // return true; if (!continueOnError) return false; } lBuffer = new StringBuilder(); pStarted = false; } else { pStarted = true; lLineNbr = memFile.LineNbr; } } if (lLine[0] == 'P') pStarted = true; if (pStarted) lBuffer.Append(lLine); } } return true; }
protected bool _LoadMatrix(MemFile memFile, PatternCollection patternCollection) { try { int lMatrixSize = Convert.ToInt32(memFile.ReadLine()); DFANodes = new List<DFANode>(lMatrixSize); for (int i = 1; i < lMatrixSize; i++) { // Console.Error.Write(memFile.LineNbr.ToString() + " - " + i.ToString() + " - "+lMatrixSize.ToString()); DFANode lDFANode = new DFANode(); for (int z = 0; z < 4; z++) lDFANode[z] = Convert.ToInt32(memFile.ReadPart('\t').Trim()); int lNodePatterns = Convert.ToInt32(memFile.ReadPart('\t').Trim()); if (lNodePatterns > 0) lDFANode.Attributes = new List<PatternKey>(lNodePatterns); for (int p = 0; p < lNodePatterns; p++) { int lPatternTransformation = Convert.ToInt32(memFile.ReadPart(':').Trim()); string lPatternKey = memFile.ReadPart('\t').Trim(); int lTransformation = Convert.ToInt32(memFile.ReadPart('\t').Trim()); Pattern lPattern = patternCollection.FindByKey(lPatternKey); lDFANode.Add(new PatternKey(lPattern, lTransformation)); } memFile.ReadLine(); DFANodes.Add(lDFANode); } } catch (Exception e) { return SetErrorMessage("Matrix Error - Line # " + memFile.LineNbr.ToString() + ":", e); } return false; }
public static bool ExecuteTest(MemFile memFile, string directory) { GoBoard lGoBoard = new GoBoard(19); GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard); GTPCommInternal lGTPCommInternal = new GTPCommInternal(); GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommInternal); lGTPGoBoard.Directory = directory; GTPCommand lGTcommand = new GTPCommand(""); string lInput = string.Empty; int[] lRegressionResults = new int[5]; while (!memFile.EOF) { string lBuffer = memFile.ReadLine('\n'); if ((lBuffer.Length >= 4) && (lBuffer.Substring(0, 4) == "quit")) break; if ((lBuffer.Length >= 2) && (lBuffer.Substring(0, 2) == "#?")) { GTPRegressionPattern lPattern = new GTPRegressionPattern(lBuffer); GTPRegressionResult lRegressionResult = GTPRegressionPattern.Test(lPattern, lInput); lRegressionResults[(int)lRegressionResult]++; switch (lRegressionResult) { case GTPRegressionResult.passed: /* Console.WriteLine("PASSED");*/ break; case GTPRegressionResult.PASSED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected PASS!"); break; case GTPRegressionResult.failed: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " failed: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break; case GTPRegressionResult.FAILED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected failure: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break; case GTPRegressionResult.ignore: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " ignoring '" + lPattern + "', got '" + Proper(lInput) + "'"); break; default: Console.WriteLine("ERROR!!!"); break; } } else if (lBuffer.Length > 0) { GTPCommand lGTcommand2 = new GTPCommand(lBuffer); if (lGTcommand2.Command.Length != 0) { lGTPCommInternal.SendToEngine(lBuffer); lGTPCommInternal.SendToEngine("\n"); lInput = lGTPCommInternal.GetResponse(); lGTcommand = lGTcommand2; } } } for (int lRegressionResultIndex = 0; lRegressionResultIndex < 5; lRegressionResultIndex++) Console.WriteLine((GTPRegressionResult)lRegressionResultIndex + " " + lRegressionResults[lRegressionResultIndex]); return (lRegressionResults[3] == 0); // false, only for unexpected failures }
public bool Load(MemFile memFile, bool continueOnError) { ClearErrorMessages(); StringBuilder lBuffer = new StringBuilder(); bool pStarted = false; int lLineNbr = 0; while (!memFile.EOF) { string lLine = memFile.ReadLine('\n'); if (lLine.Trim().ToUpper() == "###MATRIX") { return(IsError()); } if (lLine.Length > 0) { if (memFile.EOF) { lBuffer.Append(lLine); } if ((lLine[0] == 'P') || memFile.EOF) { if (pStarted) { // EOF of a Pattern Pattern lPattern = new Pattern(lBuffer.ToString(), lLineNbr); if (lPattern.IsOk()) { Add(lPattern); } else { SetErrorMessage("ERROR: Unable to compile pattern - Line # " + lLineNbr.ToString() + ":", lPattern); Console.Error.WriteLine("ERROR: Unable to compile pattern."); Console.Error.WriteLine(lPattern.GetErrorMessage()); // return true; if (!continueOnError) { return(false); } } lBuffer = new StringBuilder(); pStarted = false; } else { pStarted = true; lLineNbr = memFile.LineNbr; } } if (lLine[0] == 'P') { pStarted = true; } if (pStarted) { lBuffer.Append(lLine); } } } return(true); }
public static bool ExecuteTest(MemFile memFile, string directory) { GoBoard lGoBoard = new GoBoard(19); GTPGoBoard lGTPGoBoard = new GTPGoBoard(lGoBoard); GTPCommInternal lGTPCommInternal = new GTPCommInternal(); GTPEngine lGTPEngine = new GTPEngine(lGTPGoBoard, lGTPCommInternal); lGTPGoBoard.Directory = directory; GTPCommand lGTcommand = new GTPCommand(""); string lInput = string.Empty; int[] lRegressionResults = new int[5]; while (!memFile.EOF) { string lBuffer = memFile.ReadLine('\n'); if ((lBuffer.Length >= 4) && (lBuffer.Substring(0, 4) == "quit")) { break; } if ((lBuffer.Length >= 2) && (lBuffer.Substring(0, 2) == "#?")) { GTPRegressionPattern lPattern = new GTPRegressionPattern(lBuffer); GTPRegressionResult lRegressionResult = GTPRegressionPattern.Test(lPattern, lInput); lRegressionResults[(int)lRegressionResult]++; switch (lRegressionResult) { case GTPRegressionResult.passed: /* Console.WriteLine("PASSED");*/ break; case GTPRegressionResult.PASSED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected PASS!"); break; case GTPRegressionResult.failed: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " failed: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break; case GTPRegressionResult.FAILED: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " unexpected failure: Correct '" + lPattern + "', got '" + Proper(lInput) + "'"); break; case GTPRegressionResult.ignore: Console.WriteLine(lGTcommand.ToString()); Console.WriteLine(lGTcommand.CommandNbr.ToString() + " ignoring '" + lPattern + "', got '" + Proper(lInput) + "'"); break; default: Console.WriteLine("ERROR!!!"); break; } } else if (lBuffer.Length > 0) { GTPCommand lGTcommand2 = new GTPCommand(lBuffer); if (lGTcommand2.Command.Length != 0) { lGTPCommInternal.SendToEngine(lBuffer); lGTPCommInternal.SendToEngine("\n"); lInput = lGTPCommInternal.GetResponse(); lGTcommand = lGTcommand2; } } } for (int lRegressionResultIndex = 0; lRegressionResultIndex < 5; lRegressionResultIndex++) { Console.WriteLine((GTPRegressionResult)lRegressionResultIndex + " " + lRegressionResults[lRegressionResultIndex]); } return(lRegressionResults[3] == 0); // false, only for unexpected failures }