Esempio n. 1
0
        private void ReadGamesList(List <string> lines)
        {
            IGSGameInfo gameInfo;

            if (lines.Count == 2)
            {
                var info = lines[1];
                gameInfo = IGSGameInfo.Parse(info);
                IGSGameInfoRequest matchingRequest = null;
                foreach (var request in gameInfoRequests)
                {
                    if (request.GameNumber == gameInfo.GameNumber)
                    {
                        matchingRequest = request;
                    }
                }

                if (matchingRequest != null)
                {
                    matchingRequest.RequestCompleted(gameInfo);
                    gameInfoRequests.Remove(matchingRequest);
                    return;
                }
            }

            Games = new IGSGameInfo[lines.Count - 1];
            for (var i = 1; i < lines.Count; i++)
            {
                var line = lines[i];
                gameInfo = IGSGameInfo.Parse(line);
                Games[lines.IndexOf(line) - 1] = gameInfo;
            }
            OnGameListUpdated(EventArgs.Empty);
        }
Esempio n. 2
0
        public static IGSGameInfo Parse(string line)
        {
            var gameInfo          = new IGSGameInfo();
            var regularExpression = new Regex(@"\s+");

            try
            {
                var items = regularExpression.Replace(line.Replace('[', ' ').Replace(']', ' ').
                                                      Replace('(', ' ').Replace(')', ' '), " ").
                            Substring(1).Split(' ');

                gameInfo.GameNumber  = Convert.ToInt32(items[0]);
                gameInfo.WhitePlayer = items[1];
                gameInfo.WhiteRank   = new IGSRank(items[2]);
                gameInfo.BlackPlayer = items[4];
                gameInfo.BlackRank   = new IGSRank(items[5]);
                gameInfo.MovesMade   = Convert.ToInt32(items[6]);
                gameInfo.BoardSize   = Convert.ToByte(items[7]);
                gameInfo.Handicap    = Convert.ToByte(items[8]);

                gameInfo.Komi  = Convert.ToSingle(items[9].Split('.')[0]);
                gameInfo.Komi += Math.Sign(gameInfo.Komi) * Convert.ToSingle(items[9].Split('.')[1]) / 10;

                gameInfo.Byouyomi       = Convert.ToInt32(items[10]);
                gameInfo.GameType       = items[11];
                gameInfo.ObserversCount = Convert.ToInt32(items[12]);
            }
            catch (FormatException)
            {
                throw new IGSParseException("Corrupted game info: " + line);
            }
            catch (IndexOutOfRangeException)
            {
                throw new IGSParseException("Corrupted game info: " + line);
            }

            return(gameInfo);
        }
Esempio n. 3
0
 public void RequestCompleted(IGSGameInfo result)
 {
     Result = result;
     callback(this, new EventArgs());
 }