public override void OnEnter(PgnMove currentMove) { _currentVariation = new PgnVariation(); currentMove.Variation.Add(_currentVariation); _currentMove = new PgnMove(); }
private void Terminate(string result, PgnGame currentGame) { CheckToFinishMove(); if (!string.IsNullOrWhiteSpace(_currentMove.Move)) { currentGame.AddMove(_currentMove); } currentGame.Result = result; _stateBuffer.Clear(); _currentMove = new PgnMove(); }
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); }
public override void OnEnter(PgnMove currentMove) { base.OnEnter(currentMove); }
public virtual void OnEnter(PgnMove currentMove) { _currentMove = currentMove; _stateBuffer.Clear(); }
public void ChangeState(PgnParserState newState, PgnMove currentMove = null) { _statemachine.SetState(newState); newState.OnEnter(currentMove); }
public void AddMove(PgnMove _currentMove) { _moves.Add(_currentMove); }
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); }
public override void OnEnter(PgnMove currentMove) { _currentMove = currentMove; }
internal void InitGame(PgnGame game) { _stateBuffer.Clear(); _currentMove = new PgnMove(); }
public void Add(PgnMove move) { _variation.Add(move); }