コード例 #1
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        Game HandleSetup(SGFProperty p)
        {
            Content c;

            if (p.Name == "AE")
            {
                c = Content.Empty;
            }
            else if (p.Name == "AW")
            {
                c = Content.White;
            }
            else
            {
                c = Content.Black;
            }
            foreach (var v in p.Values)
            {
                if (v.IsComposed)
                {
                    SetupMove(v.MoveA, v.MoveB, c);
                }
                else
                {
                    SetupMove(v.Move, c);
                }
            }
            return(this);
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        /// <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)
        {
            SGFProperty p = sgfProperties.SingleOrDefault(x => x.Name == ColorToSGFProp[c]);

            if (p == null)
            {
                p = new SGFProperty()
                {
                    Name = ColorToSGFProp[c]
                };
                sgfProperties.Add(p);
            }
            string       composed = Point.ConvertToSGF(x1, y1) + ":" + Point.ConvertToSGF(x2, y2);
            SGFPropValue v        = new SGFPropValue(composed);

            p.Values.Add(v);
            for (int i = x1; i <= x2; i++)
            {
                for (int j = y1; j <= y2; j++)
                {
                    Board[i, j] = c;
                }
            }
            setupMoves = null;
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        private void RemoveProperty(string name)
        {
            SGFProperty prop = sgfProperties.SingleOrDefault(x => x.Name == name);

            if (prop != null)
            {
                sgfProperties.Remove(prop);
            }
        }
コード例 #4
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandlePlayerTurn(SGFProperty p)
 {
     if (GameInfo != null)
     {
         GameInfo.StartingPlayer = p.Values[0].Turn;
     }
     Turn = p.Values[0].Turn;
     return(this);
 }
コード例 #5
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 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);
 }
コード例 #6
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        Game HandleMove(SGFProperty p)
        {
            Content c = (p.Name == "W" ? Content.White : Content.Black);

            Turn = c;
            if (p.Values[0].Value == "")
            {
                return(Pass());
            }
            return(MakeMove(p.Values[0].Move));
        }
コード例 #7
0
ファイル: SGFNode.cs プロジェクト: nerai/GoSharp
 internal void Read(TextReader sr)
 {
     char c = (char)sr.Read();
     if (c != ';')
         throw new InvalidDataException("Node doesn't begin with a ';'.");
     sr.EatWS();
     while (char.IsUpper((char)sr.Peek()))
     {
         SGFProperty prop = new SGFProperty();
         prop.Read(sr);
         Properties.Add(prop);
         sr.EatWS();
     }
 }
コード例 #8
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        Game HandleBoardSize(SGFProperty p)
        {
            SGFPropValue v = p.Values[0];

            if (v.IsComposed)
            {
                GameInfo.BoardSizeX = v.NumX;
                GameInfo.BoardSizeY = v.NumY;
            }
            else
            {
                GameInfo.BoardSizeX = GameInfo.BoardSizeY = v.Num;
            }
            return(this);
        }
コード例 #9
0
        internal void Read(TextReader sr)
        {
            char c = (char)sr.Read();

            if (c != ';')
            {
                throw new InvalidDataException("Node doesn't begin with a ';'.");
            }
            sr.EatWS();
            while (char.IsUpper((char)sr.Peek()))
            {
                SGFProperty prop = new SGFProperty();
                prop.Read(sr);
                Properties.Add(prop);
                sr.EatWS();
            }
        }
コード例 #10
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        /// <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)
        {
            SGFProperty p = sgfProperties.SingleOrDefault(z => z.Name == ColorToSGFProp[c]);

            if (p == null)
            {
                p = new SGFProperty()
                {
                    Name = ColorToSGFProp[c]
                };
                sgfProperties.Add(p);
            }
            SGFPropValue v = new SGFPropValue(Point.ConvertToSGF(x, y));

            p.Values.Add(v);
            Board[x, y] = c;
            setupMoves  = null;
        }
コード例 #11
0
ファイル: Game.cs プロジェクト: serd/GoSharp
        private void SetProperty(string name, string value, bool create)
        {
            SGFProperty prop = sgfProperties.SingleOrDefault(x => x.Name == name);

            if (prop == null && !create)
            {
                return;
            }
            if (prop == null)
            {
                sgfProperties.Add(new SGFProperty
                {
                    Name   = name,
                    Values = new List <SGFPropValue> {
                        new SGFPropValue(value)
                    }
                });
            }
            else
            {
                prop.Values[0].Value = value;
            }
        }
コード例 #12
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 /// <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)
 {
     SGFProperty p = sgfProperties.SingleOrDefault(x => x.Name == ColorToSGFProp[c]);
     if (p == null)
     {
         p = new SGFProperty() { Name = ColorToSGFProp[c] };
         sgfProperties.Add(p);
     }
     string composed = Point.ConvertToSGF(x1, y1) + ":" + Point.ConvertToSGF(x2, y2);
     SGFPropValue v = new SGFPropValue(composed);
     p.Values.Add(v);
     for (int i = x1; i <= x2; i++)
     {
         for (int j = y1; j <= y2; j++)
         {
             Board[i, j] = c;
         }
     }
     setupMoves = null;
 }
コード例 #13
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandleBR(SGFProperty p)
 {
     GameInfo.BlackRank = p.Values[0].Value;
     return(this);
 }
コード例 #14
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandleWR(SGFProperty p)
 {
     GameInfo.WhiteRank = p.Values[0].Value;
     return(this);
 }
コード例 #15
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandleBP(SGFProperty p)
 {
     GameInfo.BlackPlayer = p.Values[0].Value;
     return(this);
 }
コード例 #16
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandleWP(SGFProperty p)
 {
     GameInfo.WhitePlayer = p.Values[0].Value;
     return(this);
 }
コード例 #17
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandleKomi(SGFProperty p)
 {
     GameInfo.Komi = p.Values[0].Double;
     return(this);
 }
コード例 #18
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 Game HandleMove(SGFProperty p)
 {
     Content c = (p.Name == "W" ? Content.White : Content.Black);
     Turn = c;
     if (p.Values[0].Value == "") return Pass();
     return MakeMove(p.Values[0].Move);
 }
コード例 #19
0
ファイル: Game.cs プロジェクト: serd/GoSharp
 Game HandleHandicap(SGFProperty p)
 {
     GameInfo.Handicap = p.Values[0].Num;
     return(this);
 }
コード例 #20
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 Game HandleSetup(SGFProperty p)
 {
     Content c;
     if (p.Name == "AE") c = Content.Empty;
     else if (p.Name == "AW") c = Content.White;
     else c = Content.Black;
     foreach (var v in p.Values)
     {
         if (v.IsComposed)
             SetupMove(v.MoveA, v.MoveB, c);
         else
             SetupMove(v.Move, c);
     }
     return this;
 }
コード例 #21
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 Game HandlePlayerTurn(SGFProperty p)
 {
     if (GameInfo != null) GameInfo.StartingPlayer = p.Values[0].Turn;
     Turn = p.Values[0].Turn;
     return this;
 }
コード例 #22
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 Game HandleHandicap(SGFProperty p)
 {
     GameInfo.Handicap = p.Values[0].Num;
     return this;
 }
コード例 #23
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 /// <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)
 {
     SGFProperty p = sgfProperties.SingleOrDefault(z => z.Name == ColorToSGFProp[c]);
     if (p == null)
     {
         p = new SGFProperty() { Name = ColorToSGFProp[c] };
         sgfProperties.Add(p);
     }
     SGFPropValue v = new SGFPropValue(Point.ConvertToSGF(x, y));
     p.Values.Add(v);
     Board[x, y] = c;
     setupMoves = null;
 }
コード例 #24
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 Game HandleBoardSize(SGFProperty p)
 {
     SGFPropValue v = p.Values[0];
     if (v.IsComposed)
     {
         GameInfo.BoardSizeX = v.NumX;
         GameInfo.BoardSizeY = v.NumY;
     }
     else
         GameInfo.BoardSizeX = GameInfo.BoardSizeY = v.Num;
     return this;
 }
コード例 #25
0
ファイル: Game.cs プロジェクト: nerai/GoSharp
 Game HandleKomi(SGFProperty p)
 {
     GameInfo.Komi = p.Values[0].Double;
     return this;
 }