Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void Apply(IMarkingsProvider markings, Path path)
        {
            if (Applies(path))
            {
                if (path.AllowMove)
                {
                    markings.Mark(path.Start, path.Squares.TakeWhile(square => square.Item2.IsEmpty)
                                  .Select((target, idx) => new MoveMarker(
                                              GetMove(new SimpleMove(path.Start, target.Item1), idx), path.Direction)).ToArray()
                                  );
                }

                if (path.AllowTake)
                {
                    markings.Mark(path.Start, path.Squares.SkipWhile((square) => path.AllowMove && square.Item2.IsEmpty)
                                  .TakeWhile((square, idx) => !square.Item2.IsEmpty && square.Item2.Color != path.Piece.Color
                                             ).Take(1)
                                  .Select((target, idx) => new MoveMarker(
                                              GetMove(new SimpleMove(path.Start, target.Item1), idx), path.Direction)).ToArray()
                                  );
                }
            }

            if (Continue(path))
            {
                base.Apply(markings, path);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public override void Apply(IMarkingsProvider markings, Path path)
        {
            if (path.Squares.Any())
            {
                var         squares   = path.Squares.ToList();
                CheckMarker marker    = default;
                var         kingColor = Color.None;

                var i = 0;

                for (; i < squares.Count; i++)
                {
                    var(target, targetPiece) = squares[i];

                    if (targetPiece.IsEmpty)
                    {
                        continue;
                    }

                    if (kingColor == Color.None && targetPiece.Color != path.Piece.Color &&
                        targetPiece.Type == PieceType.King)
                    {
                        kingColor = targetPiece.Color;

                        marker = new CheckMarker(path.Start, path.Piece, target, path.Direction);
                        continue;
                    }
                    // Stop on Piece of Kings Color
                    if (targetPiece.Type != PieceType.King && targetPiece.Color == kingColor ||
                        targetPiece.Type == PieceType.King && targetPiece.Color != kingColor)
                    {
                        break;
                    }
                    // Include Piece Not of Kings color
                    if (targetPiece.Type == PieceType.Empty || targetPiece.Color == kingColor)
                    {
                        continue;
                    }
                    i++;
                    break;
                }

                if (marker != null)
                {
                    for (i--; i > -1; i--)
                    {
                        var(target, _) = squares[i];

                        markings.Mark(target, marker);
                    }

                    markings.Mark(path.Start, marker);
                }
            }

            base.Apply(markings, path);
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override void Apply(IMarkingsProvider markings, Path path)
        {
            if (path.Squares.Any())
            {
                var pinned = (new Point(-1, -1), Piece.Empty);

                foreach (var target in path.Squares.Where(target => !target.Item2.IsEmpty))
                {
                    if (pinned.Item2.IsEmpty)
                    {
                        pinned = target;
                        continue;
                    }

                    if (target.Item2.Type != PieceType.King ||
                        target.Item2.Color != pinned.Item2.Color ||
                        path.Piece.Color == target.Item2.Color)
                    {
                        break;
                    }


                    markings.Mark(pinned.Item1, new SimpleMarker(MarkerType.Pin, path.Start, path.Piece, path.Direction));

                    break;
                }
            }

            base.Apply(markings, path);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public override void Apply(IMarkingsProvider markings, Path path)
        {
            if (path.Squares.Any())
            {
                foreach (var(target, piece) in path.Squares)
                {
                    markings.Mark(target, new SimpleMarker(MarkerType.Cover, path.Start, path.Piece, path.Direction));

                    if (!piece.IsEmpty)
                    {
                        break;
                    }
                }
            }
            base.Apply(markings, path);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override void Apply(IMarkingsProvider markings, Path path)
        {
            if (path.AllowTake && path.Piece.Type == PieceType.Pawn && path.Squares.Any())
            {
                var(target, _) = path.Squares.First();

                SimpleMarker marker;
                if ((marker = markings.GetMarkers <SimpleMarker>(target, MarkerType.EnPassant).FirstOrDefault()) != null &&
                    path.Piece.Color != marker.Piece.Color)
                {
                    markings.Mark(path.Start, new MoveMarker(new EnPassantTakeMove(path.Start, target, marker.Source), path.Direction));

                    return;
                }
            }
            base.Apply(markings, path);
        }
Ejemplo n.º 6
0
        public override void Apply(IMarkingsProvider markings, Path path)
        {
            if (path.Piece.Type == PieceType.King && !path.AllowTake)
            {
                var(point, piece) = path.Squares.SkipWhile((tuple, i) => tuple.Item2.IsEmpty).FirstOrDefault();
                if (!piece.HasMoved && piece.Type == PieceType.Rook && path.Piece.Color == piece.Color &&
                    !markings.GetKingMarkers <CheckMarker>(path.Piece.Color).Any())
                {
                    markings.Mark(path.Start, new MoveMarker(new CastleMove(
                                                                 new SimpleMove(path.Start, path.Start.PolarOffset(path.Direction, 2)),
                                                                 new SimpleMove(point, path.Start.PolarOffset(path.Direction, 1))
                                                                 ), path.Direction));
                }

                return;
            }
            base.Apply(markings, path);
        }
Ejemplo n.º 7
0
 public void Mark <T>(Point point, params T[] markers) where T : IMarker
 {
     m_markings.Mark(point, markers.Where(marker => m_predicate.Invoke(marker)).ToArray());
 }