Beispiel #1
0
        /// <summary>
        /// Verifies the specified SGF coordinates translate correctly.
        /// </summary>
        /// <param name="coordinate">The coordinate.</param>
        /// <returns></returns>
        public static bool VerifySGF(int boardSize, string coordinate, string outVariation)
        {
            int lPoint = CoordinateSystem.AtFromSGF(coordinate, boardSize);

            CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(boardSize);

            string lCoordinate = lCoord.ToString(lPoint);

            Assert.AreEqual(outVariation.ToLower(), lCoordinate.ToLower(), coordinate);

            return(outVariation.ToLower() == lCoordinate.ToLower());
        }
		public void BestMove()
		{
			int lBoardSize = 9;
			MoveList lMoveList = new MoveList(lBoardSize);

			lMoveList.Add(CoordinateSystem.AtFromSGF("C4", lBoardSize), 4);
			lMoveList.Add(CoordinateSystem.AtFromSGF("A6", lBoardSize), 6);
			lMoveList.Add(CoordinateSystem.AtFromSGF("A5", lBoardSize), 5);
			lMoveList.Add(CoordinateSystem.AtFromSGF("E1", lBoardSize), 7);
			lMoveList.Add(CoordinateSystem.AtFromSGF("A3", lBoardSize), 3);
			lMoveList.Add(CoordinateSystem.AtFromSGF("D2", lBoardSize), 2);

			Assert.AreEqual(CoordinateSystem.AtFromSGF("E1", lBoardSize), lMoveList.GetBestMove());
			lMoveList.QuickSort();

		}
        public bool RetrieveGame(GameRecord gameRecord)
        {
            switch (PropertyID)
            {
            case "S":
            {
                string lMoves = Text;

                // Note: SmartGo includes \n and \r characters in the list of moves
                while (lMoves.IndexOf('\n') >= 0)
                {
                    lMoves = lMoves.Remove(lMoves.IndexOf('\n'));
                }

                while (lMoves.IndexOf('\r') >= 0)
                {
                    lMoves = lMoves.Remove(lMoves.IndexOf('\r'));
                }

                // Compressed SFG
                if (lMoves.Length % 2 != 0)
                {
                    return(false);
                }

                for (int i = 0; i < lMoves.Length / 2; i++)
                {
                    string lText = lMoves.Substring(i * 2, 2);

                    gameRecord.PlayStone(CoordinateSystem.AtFromSGF(lText, gameRecord.BoardSize));
                }

                return(true);
            }

            case "W":
            {
                if (Text.Length == 0)
                {
                    gameRecord.PlayStone(Color.White, CoordinateSystem.PASS);
                    return(true);
                }

                if (Text.Length != 2)
                {
                    return(false);
                }

                gameRecord.PlayStone(Color.White, CoordinateSystem.AtFromSGF(Text, gameRecord.BoardSize));

                return(true);
            }

            case "B":
            {
                if (Text.Length == 0)
                {
                    gameRecord.PlayStone(Color.Black, CoordinateSystem.PASS);
                    return(true);
                }

                if (Text.Length != 2)
                {
                    return(false);
                }

                gameRecord.PlayStone(Color.Black, CoordinateSystem.AtFromSGF(Text, gameRecord.BoardSize));

                return(true);
            }

            case "AW":
            {
                if (Text.Length != 2)
                {
                    return(false);
                }

                gameRecord.SetupStone(Color.White, CoordinateSystem.AtFromSGF(Text, gameRecord.BoardSize));

                return(true);
            }

            case "AB":
            {
                if (Text.Length != 2)
                {
                    return(false);
                }

                gameRecord.SetupStone(Color.Black, CoordinateSystem.AtFromSGF(Text, gameRecord.BoardSize));

                return(true);
            }

            case "PL":
            {
                if (Text.Length == 0)
                {
                    return(false);
                }

                if (!Color.IsValidColor(Text))
                {
                    return(false);
                }

                gameRecord.NextPlayer = Color.ToColor(Text);

                return(true);
            }

            case "AE":
            {
                return(false);          // clear points - not implemented
            }

            case "DT":
            {
                gameRecord.Date = Text;
                return(true);
            }

            case "PB":
            {
                gameRecord.BlackPlayerName = Text;
                return(true);
            }

            case "PW":
            {
                gameRecord.WhitePlayerName = Text;
                return(true);
            }

            //				case "RS":
            //					{
            //						gameRecord.Result = Text;
            //						return true;
            //					}
            case "GN":
            {
                gameRecord.GameName = Text;
                return(true);
            }

            case "ID":
            {
                gameRecord.Identification = Text;
                return(true);
            }

            case "C":
            {
                gameRecord.Comment = Text;
                return(true);
            }

            case "RU":
            {
                gameRecord.Rules = Text;
                return(true);
            }

            case "RE":
            {
                gameRecord.Result = Text;
                return(true);
            }

            case "PC":
            {
                gameRecord.Place = Text;
                return(true);
            }

            case "BR":
            {
                gameRecord.BlackRank = Text;
                return(true);
            }

            case "WR":
            {
                gameRecord.WhiteRank = Text;
                return(true);
            }

            case "HE":
            {
                int lHandicapStones = 0;

                if (!Int32.TryParse(Text.Trim(), out lHandicapStones))
                {
                    return(false);
                }

                gameRecord.HandicapStones = lHandicapStones;

                return(true);
            }

            case "SZ":
            {
                int lBoardSize = 0;

                if (!Int32.TryParse(Text.Trim(), out lBoardSize))
                {
                    return(false);
                }

                if ((lBoardSize > 19) && (lBoardSize > 1))
                {
                    return(false);
                }

                gameRecord.BoardSize = lBoardSize;

                return(true);
            }

            case "TW":
            {
                if (Text.Length != 2)
                {
                    return(false);
                }

                gameRecord.SetTerritory(Color.White, CoordinateSystem.AtFromSGF(Text, gameRecord.BoardSize));

                return(true);
            }

            case "TB":
            {
                if (Text.Length != 2)
                {
                    return(false);
                }

                gameRecord.SetTerritory(Color.Black, CoordinateSystem.AtFromSGF(Text, gameRecord.BoardSize));

                return(true);
            }

            default:
                return(true);
            }
        }