private void BuildJumpSequences(Figure figure, MoveSequence sequence, List <MoveSequence> builder)
        {
            if (ShouldPromoteKing(figure, board.Size))
            {
                sequence.Add(MoveStep.King());
                builder.Add(sequence); //abort sequence traversing
                return;
            }

            var endOfSequence = true;

            foreach (var direction in GetDirections(figure))
            {
                var position = GetJumpPoint(figure, direction, out var neighbour);
                if (position == Point.Nop)
                {
                    continue;
                }
                if (sequence.Contains(position))
                {
                    continue;
                }

                endOfSequence = false;
                var figureAfterJump = new Figure(position, figure.Side, figure.IsKing);
                var newSequence     = new MoveSequence(sequence);
                newSequence.Add(MoveStep.Jump(figureAfterJump.Point));
                BuildJumpSequences(figureAfterJump, newSequence, builder);
            }
            if (endOfSequence && !sequence.IsEmpty)
            {
                builder.Add(sequence);
            }
        }
 private void BuildSimpleMoves(Figure figure, List <MoveSequence> simpleMoves)
 {
     foreach (var direction in GetDirections(figure))
     {
         var jump = GetJumpPoint(figure, direction, out var neighbour);
         if (jump == Point.Nop && neighbour.Side == Side.Empty)
         {
             var sequence = new MoveSequence(MoveStep.Move(neighbour.Point));
             if (!figure.IsKing && ShouldPromoteKing(new Figure(neighbour.Point, figure.Side, figure.IsKing), board.Size))
             {
                 sequence.Add(MoveStep.King());
             }
             simpleMoves.Add(sequence);
         }
     }
 }
Esempio n. 3
0
 public bool Equals(MoveStep other) => Type == other.Type && Target == other.Target;