private Game HandleSetup(SGFProperty p) { Content c; switch (p.Name) { case "AE": c = Content.Empty; break; case "AW": c = Content.White; break; default: c = Content.Black; break; } foreach (var v in p.Values) { if (v.IsComposed) { SetupMove(v.MoveA, v.MoveB, c); } else { SetupMove(v.Move, c); } } return(this); }
private Game HandleMove(SGFProperty p) { var c = (p.Name == "W" ? Content.White : Content.Black); Turn = c; return(p.Values[0].Value == "" ? Pass() : MakeMove(p.Values[0].Move)); }
/// <summary> /// Adds stones to the board in a rectangular area. /// </summary> /// <param name="x1">The left coordinate of the rectangle.</param> /// <param name="y1">The top coordinate of the rectangle.</param> /// <param name="x2">The right coordinate of the rectangle.</param> /// <param name="y2">The bottom coordinate of the rectangle.</param> /// <param name="c">The color of the stone to add (or empty to clear).</param> public void SetupMove(int x1, int y1, int x2, int y2, Content c) { var p = _sgfProperties.SingleOrDefault(x => x.Name == ColorToSGFProp[c]); if (p == null) { p = new SGFProperty() { Name = ColorToSGFProp[c] }; _sgfProperties.Add(p); } var composed = $"{Point.ConvertToSGF(x1, y1)}:{Point.ConvertToSGF(x2, y2)}"; var v = new SGFPropValue(composed); p.Values.Add(v); for (var i = x1; i <= x2; i++) { for (var j = y1; j <= y2; j++) { Board[i, j] = c; } } _setupMoves = null; }
private Game HandleTM(SGFProperty p) { if (string.IsNullOrEmpty(p.Values[0].Value)) { throw new Exception("Invalid game."); } GameInfo.MainTime = TimeSpan.FromSeconds(p.Values[0].Num); return(this); }
private Game HandlePlayerTurn(SGFProperty p) { if (GameInfo != null) { GameInfo.StartingPlayer = p.Values[0].Turn; } Turn = p.Values[0].Turn; return(this); }
private Game HandleBoardSize(SGFProperty p) { var v = p.Values[0]; if (v.IsComposed) { GameInfo.BoardSizeX = v.NumX; GameInfo.BoardSizeY = v.NumY; } else { GameInfo.BoardSizeX = GameInfo.BoardSizeY = v.Num; } return(this); }
internal void Read(TextReader sr) { var c = (char)sr.Read(); if (c != ';') { throw new InvalidDataException("Node doesn't begin with a ';'."); } sr.EatWS(); while (char.IsUpper((char)sr.Peek())) { var prop = new SGFProperty(); prop.Read(sr); Properties.Add(prop); sr.EatWS(); } }
/// <summary> /// Adds a stone to the board as a setup move. /// </summary> /// <param name="x">The X coordinate of the setup move.</param> /// <param name="y">The Y coordinate of the setup move.</param> /// <param name="c">The color of the stone to add (or empty to clear).</param> public void SetupMove(int x, int y, Content c) { var p = _sgfProperties.SingleOrDefault(z => z.Name == ColorToSGFProp[c]); if (p == null) { p = new SGFProperty() { Name = ColorToSGFProp[c] }; _sgfProperties.Add(p); } var v = new SGFPropValue(Point.ConvertToSGF(x, y)); p.Values.Add(v); Board[x, y] = c; _setupMoves = null; }
private Game HandleBR(SGFProperty p) { GameInfo.BlackRank = p.Values[0].Value; return(this); }
private Game HandleWR(SGFProperty p) { GameInfo.WhiteRank = p.Values[0].Value; return(this); }
private Game HandleBP(SGFProperty p) { GameInfo.BlackPlayer = p.Values[0].Value; return(this); }
private Game HandleWP(SGFProperty p) { GameInfo.WhitePlayer = p.Values[0].Value; return(this); }
private Game HandleKomi(SGFProperty p) { GameInfo.Komi = p.Values[0].Double; return(this); }
private Game HandleHandicap(SGFProperty p) { GameInfo.Handicap = p.Values[0].Num; return(this); }