public override string ToString() { SGFCollection lSGFCollection = new SGFCollection(); SGFSequence lSGFSequence = new SGFSequence(); SGFNode lSGFNode = new SGFNode(); CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(BoardSize); lSGFNode.AddProperty(new SGFProperty("GM", "1")); lSGFNode.AddProperty(new SGFProperty("FF", "4")); lSGFNode.AddProperty(new SGFProperty("CA", "UTF-8")); lSGFNode.AddProperty(new SGFProperty("SZ", BoardSize)); lSGFNode.AddProperty(new SGFProperty("KM", Convert.ToString(Komi))); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("GN", GameName)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("ID", Identification)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("DT", Date)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PB", BlackPlayerName)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PW", WhitePlayerName)); // lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RS", Result)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("C", Comment)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RU", Rules)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PC", Place)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("WR", WhiteRank)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("BR", BlackRank)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RE", Result)); if (TimeLimit != 0) lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("TM", TimeLimit)); if (HandicapStones > 0) lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("HE", HandicapStones)); lSGFSequence.AddNode(lSGFNode); foreach (GameMove lGameMove in Moves) { lSGFNode = new SGFNode(); lSGFNode.AddProperty(new SGFProperty( (lGameMove.SetupMove ? "A" : "") + (lGameMove.Player.IsBlack ? "B" : "W") , lCoord.ToSGFString(lGameMove.Move))); lSGFSequence.AddNode(lSGFNode); } if ((Territory[0].Count != 0) || (Territory[1].Count != 0)) { lSGFNode = new SGFNode(); for (int lTerritoryIndex = 0; lTerritoryIndex < 2; lTerritoryIndex++) { if (Territory[lTerritoryIndex].Count != 0) { foreach (int lIndex in Territory[lTerritoryIndex]) { lSGFNode.AddProperty(new SGFProperty( "T" + (lTerritoryIndex == 0 ? "B" : "W"), lCoord.ToSGFString(lIndex))); } } } lSGFSequence.AddNode(lSGFNode); } lSGFCollection.AddSequence(lSGFSequence); return lSGFCollection.ToString(); }
public bool Read(MemFile memFile) { char c = memFile.Get(); if (c != '(') { return(SetErrorMessage("Expecting open-parentheses, found: " + c.ToString())); } while (true) { c = memFile.Peek(); if (c == '(') { SGFSequence lSGFSequence = new SGFSequence(memFile); if (lSGFSequence.IsError()) { return(SetErrorMessage(lSGFSequence)); } AddVariation(lSGFSequence); char p = memFile.Get(); if (p != ')') // eat this character { return(SetErrorMessage("Expecting closing-parenthese, found: " + p.ToString())); } } else { if (c == ')') { break; } if (c == ';') { SGFNode lSGFNode = new SGFNode(memFile); if (lSGFNode.IsError()) { return(SetErrorMessage(lSGFNode)); } AddNode(lSGFNode); } else { memFile.Get(); // eat this character } } if (memFile.EOF) { return(SetErrorMessage("Unexpected EOF.")); } } return(true); }
public void AddNode(SGFNode pSGFNode) { Nodes.Add(pSGFNode); }
public bool Read(MemFile memFile) { char c = memFile.Get(); if (c != '(') return SetErrorMessage("Expecting open-parentheses, found: " + c.ToString()); while (true) { c = memFile.Peek(); if (c == '(') { SGFSequence lSGFSequence = new SGFSequence(memFile); if (lSGFSequence.IsError()) return SetErrorMessage(lSGFSequence); AddVariation(lSGFSequence); char p = memFile.Get(); if (p != ')') // eat this character return SetErrorMessage("Expecting closing-parenthese, found: " + p.ToString()); } else { if (c == ')') break; if (c == ';') { SGFNode lSGFNode = new SGFNode(memFile); if (lSGFNode.IsError()) return SetErrorMessage(lSGFNode); AddNode(lSGFNode); } else memFile.Get(); // eat this character } if (memFile.EOF) return SetErrorMessage("Unexpected EOF."); } return true; }
public override string ToString() { SGFCollection lSGFCollection = new SGFCollection(); SGFSequence lSGFSequence = new SGFSequence(); SGFNode lSGFNode = new SGFNode(); CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(BoardSize); lSGFNode.AddProperty(new SGFProperty("GM", "1")); lSGFNode.AddProperty(new SGFProperty("FF", "4")); lSGFNode.AddProperty(new SGFProperty("CA", "UTF-8")); lSGFNode.AddProperty(new SGFProperty("SZ", BoardSize)); lSGFNode.AddProperty(new SGFProperty("KM", Convert.ToString(Komi))); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("GN", GameName)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("ID", Identification)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("DT", Date)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PB", BlackPlayerName)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PW", WhitePlayerName)); // lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RS", Result)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("C", Comment)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RU", Rules)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PC", Place)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("WR", WhiteRank)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("BR", BlackRank)); lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RE", Result)); if (TimeLimit != 0) { lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("TM", TimeLimit)); } if (HandicapStones > 0) { lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("HE", HandicapStones)); } lSGFSequence.AddNode(lSGFNode); foreach (GameMove lGameMove in Moves) { lSGFNode = new SGFNode(); lSGFNode.AddProperty(new SGFProperty( (lGameMove.SetupMove ? "A" : "") + (lGameMove.Player.IsBlack ? "B" : "W") , lCoord.ToSGFString(lGameMove.Move))); lSGFSequence.AddNode(lSGFNode); } if ((Territory[0].Count != 0) || (Territory[1].Count != 0)) { lSGFNode = new SGFNode(); for (int lTerritoryIndex = 0; lTerritoryIndex < 2; lTerritoryIndex++) { if (Territory[lTerritoryIndex].Count != 0) { foreach (int lIndex in Territory[lTerritoryIndex]) { lSGFNode.AddProperty(new SGFProperty( "T" + (lTerritoryIndex == 0 ? "B" : "W"), lCoord.ToSGFString(lIndex))); } } } lSGFSequence.AddNode(lSGFNode); } lSGFCollection.AddSequence(lSGFSequence); return(lSGFCollection.ToString()); }