/// <summary> /// Creates a library item from file content info. Displays error info. /// </summary> /// <param name="fileInfo">File content info</param> /// <returns>Library item</returns> public async Task <LibraryItem> CreateLibraryItemFromFileContentAsync(FileContentInfo fileInfo) { if (fileInfo == null) { return(null); } var parser = new SgfParser(); SgfCollection collection = null; try { collection = parser.Parse(fileInfo.Contents); } catch (SgfParseException e) { //ignore await _dialogService.ShowAsync(e.Message, Localizer.ErrorParsingSgfFile); } if (collection != null) { var newItem = CreateLibraryItem(fileInfo, collection); return(newItem); } return(null); }
/// <summary> /// Creates a tsumego problem from the contents of an SGF file downloaded from online-go.com using /// the Ruby downloader. /// </summary> /// <param name="data">The contents of an SGF file.</param> /// <returns></returns> public static TsumegoProblem CreateFromSgfText(string data) { SgfParser parser = new SgfParser(); var collection = parser.Parse(data); SgfGameTree sgfTree = collection.GameTrees.First(); string problemName = ""; StoneColor playerToPlay = StoneColor.None; foreach (var node in sgfTree.Sequence) { if (node["GN"] != null) { problemName = node["GN"].Value <string>(); } if (node["PL"] != null) { SgfColor sgfColor = node["PL"].Value <SgfColor>(); switch (sgfColor) { case SgfColor.Black: playerToPlay = StoneColor.Black; break; case SgfColor.White: playerToPlay = StoneColor.White; break; } } } return(new TsumegoProblem(problemName, sgfTree, playerToPlay)); }
public void CollectionOfTwoMinimalGameTreesIsSuccessfullySerialized() { var targetSgf = "(;)(;)"; var parser = new SgfParser(); var collection = parser.Parse(targetSgf); var serialized = new SgfSerializer().Serialize(collection); Assert.AreEqual(targetSgf, serialized); }
private void AnalyzeGame(ExternalSgfFileViewModel libraryItem, LibraryItemGame game) { SgfParser parser = new SgfParser(); var sgfCollection = parser.Parse(libraryItem.Contents); var index = Array.IndexOf(libraryItem.Games, game); var sgfGameTree = sgfCollection.GameTrees.ElementAt(index); StartAnalysis(libraryItem, sgfGameTree); }
public void SimpleSgfInputIsSuccessfullySerialized() { var targetSgf = @"(;FF[4]C[root](;C[a];C[b](;C[c])(;C[d];C[e]))(;C[f](;C[g];C[h];C[i])(;C[j];LB[ab:Hello world!])))"; var parser = new SgfParser(); var collection = parser.Parse(targetSgf); var serialized = new SgfSerializer().Serialize(collection); Assert.AreEqual(targetSgf, serialized); }
public void MinimalGameTreeIsSuccessfullyParsed() { var parser = new SgfParser(); var collection = parser.Parse("(;)"); Assert.IsFalse(parser.HasWarnings); Assert.AreEqual(1, collection.GameTrees.Count()); Assert.AreEqual(1, collection.GameTrees.First().Sequence.Count()); Assert.AreEqual(0, collection.GameTrees.First().Children.Count()); }
static void Main(string[] args) { SgfParser sgfParser = new SgfParser(); SgfCollection collection = sgfParser.Parse(File.ReadAllText("S:\\DELETEME\\markup.sgf")); SgfToGameTreeConverter gameTreeConverter = new SgfToGameTreeConverter(collection.First()); GameTreeNode rootNode = gameTreeConverter.Convert().GameTree.GameTreeRoot; //SgfParser.Deserialize(File.ReadAllText("C:\\Users\\Martin\\Downloads\\ff4_ex.sgf")); WriteMarkup(rootNode); }
public void SimpleSgfInputIsSuccessfullyParsed() { var parser = new SgfParser(); var collection = parser.Parse(@"(;FF[4]C[root](;C[a];C[b](;C[c]) (; C[ d ]; C[ e ])) (; C[ f ](; C[ g ]; C[ h ]; C[ i ]) (; C[ j ]))) "); Assert.IsFalse(parser.HasWarnings); Assert.AreEqual(1, collection.Count()); }
private async Task AnalyzeGameAsync(AppDataLibraryItemViewModel libraryItem, LibraryItemGame game) { //load from library LoadingText = Localizer.LoadingEllipsis; IsWorking = true; var sgfContents = await _appDataFileService.ReadFileAsync(libraryItem.FileName, SgfFolderName); var parser = new SgfParser(); var collection = parser.Parse(sgfContents); var index = Array.IndexOf(libraryItem.Games, game); var sgfGameTree = collection.GameTrees.ElementAt(index); StartAnalysis(libraryItem, sgfGameTree); IsWorking = false; }
/// <summary> /// Tests all files in an invalid folder for exceptions /// </summary> /// <param name="invalidFolder">Invalid SGF files folder</param> private void InvalidSgfFolderTest(string invalidFolder) { var parser = new SgfParser(); var files = SgfTestHelpers.GetSgfFiles(Path.Combine("Invalid", invalidFolder)); foreach (var file in files) { try { parser.Parse(File.ReadAllText(file)); Assert.Fail($"File {file} did not fail parsing"); } catch (SgfParseException) { //ok } } }
private LibraryItem RefreshLibraryItemBuilder(FileContentInfo fileContentInfo) { try { SgfParser parser = new SgfParser(); var sgfCollection = parser.Parse(fileContentInfo.Contents); var libraryItem = CreateLibraryItem(fileContentInfo, sgfCollection); lock (_progressLock) { _loadedLibraryItems++; } return(libraryItem); } catch { //invalid item, ignore lock (_progressLock) { _loadedLibraryItems++; } return(null); } }
public static SgfCollection ParseFile(SgfParser parser, string sampleSgfSubPath) { return(parser.Parse(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Sgf/Parsing/SampleSgfs/", sampleSgfSubPath)))); }