public static void UpdateTerritory(GameRecord gameRecord, GoBoard goBoard)
        {
            if (goBoard.BoardSize != gameRecord.BoardSize)
                throw new ApplicationException("BUG");

            gameRecord.ClearTerritory();

            for (int x = 0; x < goBoard.BoardSize; x++)
                for (int y = 0; y < goBoard.BoardSize; y++)
                {
                    SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus((goBoard.Coord.At(x, y)));

                    if (lSafetyStatus.IsAlive || lSafetyStatus.IsTerritory)
                        gameRecord.SetTerritory(lSafetyStatus.Player, goBoard.Coord.At(x, y));
                }
        }
Exemple #2
0
        public static void UpdateTerritory(GameRecord gameRecord, GoBoard goBoard)
        {
            if (goBoard.BoardSize != gameRecord.BoardSize)
            {
                throw new ApplicationException("BUG");
            }

            gameRecord.ClearTerritory();

            for (int x = 0; x < goBoard.BoardSize; x++)
            {
                for (int y = 0; y < goBoard.BoardSize; y++)
                {
                    SafetyStatus lSafetyStatus = goBoard.GetSafetyStatus((goBoard.Coord.At(x, y)));

                    if (lSafetyStatus.IsAlive || lSafetyStatus.IsTerritory)
                    {
                        gameRecord.SetTerritory(lSafetyStatus.Player, goBoard.Coord.At(x, y));
                    }
                }
            }
        }
Exemple #3
0
        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;
            }
        }
        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);
            }
        }