示例#1
0
        public override void OnEnter(PgnMove currentMove)
        {
            _currentVariation = new PgnVariation();
            currentMove.Variation.Add(_currentVariation);

            _currentMove = new PgnMove();
        }
示例#2
0
        private void Terminate(string result, PgnGame currentGame)
        {
            CheckToFinishMove();

            if (!string.IsNullOrWhiteSpace(_currentMove.Move))
            {
                currentGame.AddMove(_currentMove);
            }

            currentGame.Result = result;

            _stateBuffer.Clear();
            _currentMove = new PgnMove();
        }
示例#3
0
        protected override PgnParseResult DoParse(char current, char next, PgnGame currentGame)
        {
            if (char.IsWhiteSpace(current) && char.IsWhiteSpace(next))
            {
                //remove double whitespaces
            }
            else if (char.IsWhiteSpace(current))
            {
                CheckToFinishMove();
            }
            else if (current == '\r')
            {
                //remove linebreaks
            }
            else if (current == '-' ||
                     current == '+' ||
                     current == '#')
            {
                _stateBuffer.Add(current);
            }
            else if (char.IsLetterOrDigit(current))
            {
                if (!string.IsNullOrWhiteSpace(_currentMove.Move))
                {
                    _stateBuffer.Clear();

                    _currentMove = new PgnMove();
                }

                _stateBuffer.Add(current);
            }
            else if (current == PgnToken.Period.Token)
            {
                _stateBuffer.Clear();
            }
            else
            {
                _stateBuffer.Add(current);
                //throw new PgnReaderException("RecursiveVariationState: no idea how to handle: " + current);
            }

            return(PgnParseResult.None);
        }
示例#4
0
 public override void OnEnter(PgnMove currentMove)
 {
     base.OnEnter(currentMove);
 }
示例#5
0
 public virtual void OnEnter(PgnMove currentMove)
 {
     _currentMove = currentMove;
     _stateBuffer.Clear();
 }
示例#6
0
 public void ChangeState(PgnParserState newState, PgnMove currentMove = null)
 {
     _statemachine.SetState(newState);
     newState.OnEnter(currentMove);
 }
示例#7
0
 public void AddMove(PgnMove _currentMove)
 {
     _moves.Add(_currentMove);
 }
示例#8
0
        protected override PgnParseResult DoParse(char current, char next, PgnGame currentGame)
        {
            if (_skipCharsTilEofGame > 0)
            {
                --_skipCharsTilEofGame;
                return(_skipCharsTilEofGame == 0 ? PgnParseResult.EndOfGame : PgnParseResult.None);
            }

            if (current == '1' && next == '/')
            {
                Terminate("1/2-1/2" + "", currentGame);

                _skipCharsTilEofGame = 6;

                return(PgnParseResult.None);
            }
            else if (current == '1' && next == '-')
            {
                Terminate("1-0", currentGame);

                _skipCharsTilEofGame = 2;

                return(PgnParseResult.None);
            }
            else if (current == '0' && next == '-')
            {
                Terminate("0-1", currentGame);

                _skipCharsTilEofGame = 2;

                return(PgnParseResult.None);
            }
            else if (char.IsLetterOrDigit(current))
            {
                if (!string.IsNullOrWhiteSpace(_currentMove.Move))
                {
                    currentGame.AddMove(_currentMove);
                    _stateBuffer.Clear();

                    _currentMove = new PgnMove();
                }

                _stateBuffer.Add(current);
            }
            else if (current == PgnToken.Period.Token)
            {
                _stateBuffer.Clear();
            }
            else if (current == PgnToken.Asterisk.Token)
            {
                Terminate(current + "", currentGame);

                return(PgnParseResult.EndOfGame);
            }
            else if (current == PgnToken.TagBegin.Token || current == '\0')
            {
                string gameResult  = string.Empty;
                string termination = new string(_stateBuffer.ToArray()).Trim();
                foreach (var result in PgnReader.Results)
                {
                    if (termination.EndsWith(result))
                    {
                        gameResult = result;
                    }
                }

                if (string.IsNullOrEmpty(gameResult))
                {
                    CheckToFinishMove();
                    Terminate("*", currentGame);
                }
                else
                {
                    Terminate(gameResult, currentGame);
                }

                return(PgnParseResult.EndOfGame);
            }
            else if (char.IsWhiteSpace(current) && char.IsWhiteSpace(next))
            {
                //remove double whitespaces
            }
            else if (char.IsWhiteSpace(current))
            {
                CheckToFinishMove();

                if (next == PgnToken.TagBegin.Token)
                {
                    if (!string.IsNullOrWhiteSpace(_currentMove.Move))
                    {
                        currentGame.AddMove(_currentMove);
                    }
                    return(PgnParseResult.EndOfGame);
                }
            }
            else if (current == '\r')
            {
                //remove linebreaks
            }
            else if (current == '-' ||
                     current == '+' ||
                     current == '#')
            {
                _stateBuffer.Add(current);
            }
            else
            {
                _stateBuffer.Add(current);
                //throw new PgnReaderException("MovesSectionState: no idea how to handle: " + current);
            }

            return(PgnParseResult.None);
        }
示例#9
0
 public override void OnEnter(PgnMove currentMove)
 {
     _currentMove = currentMove;
 }
示例#10
0
 internal void InitGame(PgnGame game)
 {
     _stateBuffer.Clear();
     _currentMove = new PgnMove();
 }
示例#11
0
 public void Add(PgnMove move)
 {
     _variation.Add(move);
 }