示例#1
0
 private void BuildEndOfVariation(PgnMoveInformation pgnMoveInformation)
 {
     for (var i = 0; i > pgnMoveInformation.VariationDepthFromNext; i--)
     {
         moveTextBuilder.Append(_options.GetVariationPadding()).Append(")");
         if (_options.IndentVariations)
         {
             moveTextBuilder.Append(_options.NewLineIndicator);
         }
     }
 }
示例#2
0
        private PgnMoveBuilder BuildNumericAnnotationGlyph(PgnMoveInformation pgnMoveInformation)
        {
            var nag = pgnMoveInformation.NAG?.ToString(_options.AnnotationFormat);

            if (!string.IsNullOrWhiteSpace(nag))
            {
                moveTextBuilder.Append(_options.WhitespaceSeparator)
                .Append(nag);
            }

            return(this);
        }
示例#3
0
        public string BuildMove(PgnMoveInformation pgnMoveInformation, bool isBlackMoveNeeded = false)
        {
            BuildVariationStart(pgnMoveInformation).
            BuildMoveSeparator(pgnMoveInformation).
            BuildMoveNumber(pgnMoveInformation);
            BuildMoveValue(pgnMoveInformation, isBlackMoveNeeded).
            BuildNumericAnnotationGlyph(pgnMoveInformation).
            BuildEndOfVariation(pgnMoveInformation);
            var move = moveTextBuilder.ToString();

            moveTextBuilder.Clear();
            return(move);
        }
示例#4
0
        private PgnMoveBuilder BuildMoveNumber(PgnMoveInformation pgnMoveInformation)
        {
            var blackMoveNeeded = (pgnMoveInformation.ColorMakingMove == Color.Black &&
                                   (pgnMoveInformation.VariationDepthFromPrevious != 0 ||
                                    pgnMoveInformation.IsFirstGameMove));

            if (pgnMoveInformation.ColorMakingMove == Color.White || blackMoveNeeded)
            {
                moveTextBuilder.Append(pgnMoveInformation.MoveNumber)
                .Append(pgnMoveInformation.ColorMakingMove == Color.Black ? "..." : ".")
                .Append(_options.SpaceAfterMoveNumber ? _options.WhitespaceSeparator.ToString() : "");
            }

            return(this);
        }
示例#5
0
        public IEnumerable <MovePair> GetMovePairs()
        {
            var pair = new MovePair(null);
            var flattenedTreeNodes = FlattenToPgnOrder();
            var nodeQueue          = new Queue <MoveTreeNode <PostMoveState> >(flattenedTreeNodes);
            var lastLevel          = 0;
            MoveTreeNode <PostMoveState> previous = null;

            while (nodeQueue.TryDequeue(out var moveNode))
            {
                var currentDepth            = moveNode.VariationDepth;
                var hasNextNode             = nodeQueue.TryPeek(out var nextNodeInQueue);
                var depthDifferencePrevious = GetPreviousDepthDifference(moveNode, previous, lastLevel);
                var depthDifferenceNext     = GetNextDepthDifference(moveNode, nextNodeInQueue, currentDepth);

                var node = new PgnMoveInformation(moveNode.ColorMakingMove, moveNode.Value.San, moveNode.MoveNumber,
                                                  moveNode.IsFirstMoveInGame, !hasNextNode, depthDifferencePrevious, depthDifferenceNext,
                                                  moveNode.Comment, moveNode.Annotation);
                lastLevel = currentDepth;

                previous = moveNode;

                if (node.ColorMakingMove == Color.White)
                {
                    if (!pair.IsEmpty)
                    {
                        yield return(pair);
                    }

                    pair = new MovePair(node);
                }
                else
                {
                    pair.BlackNode = node;
                    yield return(pair);

                    pair = new MovePair(null);
                }

                if ((node.VariationDepthFromNext != 0 || node.VariationDepthFromPrevious != 0 || node.IsLastMove) &&
                    !pair.IsEmpty)
                {
                    yield return(pair);

                    pair = new MovePair(null);
                }
            }
        }
示例#6
0
        private PgnMoveBuilder BuildVariationStart(PgnMoveInformation pgnMoveInformation)
        {
            if (pgnMoveInformation.FirstMoveInVariation)
            {
                if (_options.IndentVariations)
                {
                    moveTextBuilder.Append(_options.NewLineIndicator);
                }
                else
                {
                    moveTextBuilder.Append(_options.WhitespaceSeparator);
                }
                moveTextBuilder.Append("(").Append(_options.GetVariationPadding());
            }

            return(this);
        }
示例#7
0
        private PgnMoveBuilder BuildMoveSeparator(PgnMoveInformation pgnMoveInformation)
        {
            //if a newline after Black's move is indicated, begin the line with it.
            if (_options.NewlineAfterBlackMove && pgnMoveInformation.ColorMakingMove == Color.White)
            {
                moveTextBuilder.Append(_options.NewLineIndicator);
            }
            else
            {
                //if the type is not a variation beginning and it's not the first move, prefix with a space
                if (!pgnMoveInformation.FirstMoveInVariation)
                {
                    if (!pgnMoveInformation.IsFirstGameMove)
                    {
                        moveTextBuilder.Append(_options.WhitespaceSeparator);
                    }
                }
            }

            return(this);
        }
示例#8
0
 public PgnMoveBuilder BuildMoveValue(PgnMoveInformation pgnMoveInformation, bool isBlackMoveNeeded)
 {
     moveTextBuilder.Append(pgnMoveInformation.MoveSan);
     return(this);
 }