public override void Apply(IMarkingsProvider markings, Path path)
        {
            var checkMarkers = markings.GetKingMarkers <CheckMarker>(path.Piece.Color).ToList();

            base.Apply(checkMarkers.Any() ? new MarkingFilter(marker =>
            {
                if (!(marker is MoveMarker moveMarker) || path.Piece.Type == PieceType.King)
                {
                    //   + All King moves
                    return(true);
                }
                if (checkMarkers.Count > 1)
                {
                    //   + If multiple checks, must move king
                    return(false);
                }

                var move = moveMarker.Move;

                var check = checkMarkers[0];

                //   + Take single checking piece
                if (move.To == check.Source)
                {
                    return(true);
                }

                //   + If "None" must take piece or move king otherwise intercede
                return(check.Direction != Direction.None && move.To.IsBetween(check.Source, check.KingLocation));
            }, markings) : markings, path);
        }
Exemple #2
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);
        }
Exemple #3
0
 public IEnumerable <T> GetKingMarkers <T>(Color color, params MarkerType[] types) where T : IMarker =>
 m_markings.GetKingMarkers <T>(color, types);