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); }
/// <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); }
/// <inheritdoc /> public override void Apply(IMarkingsProvider markings, Path path) { if (m_predicate.Invoke(path)) { base.Apply(markings, path); } }
/// <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); } }
public override void Apply(IMarkingsProvider markings, Path path) { if (path.Piece.Type == PieceType.King) { markings.KingLocations[path.Piece.Color] = path.Start; } base.Apply(markings, path); }
/// <inheritdoc /> public override void Apply(IMarkingsProvider markings, Path item) { if (m_predicate.Invoke(item)) { m_trueRule.Apply(markings, item); } base.Apply(markings, item); }
/// <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); }
public override void Apply(IMarkingsProvider markings, Path path) { if (Enabled && !markings.KingLocations.ContainsKey(path.Piece.Color)) { System.Console.WriteLine($"{Enabled}::{path.Piece}"); return; } base.Apply(markings, path); }
/// <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); }
/// <inheritdoc /> public override void Apply(IMarkingsProvider markings, Path path) { if (path.Squares.Any()) { var pin = markings.GetMarkers <SimpleMarker>(path.Start, MarkerType.Pin).FirstOrDefault(); if (pin != default) { if (path.Direction != pin.Direction && path.Direction != pin.Direction.Opposite()) { return; } } } base.Apply(markings, path); }
/// <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); }
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); }
/// <inheritdoc /> public override void Apply(IMarkingsProvider markings, Path path) { if (path.Piece.Type == PieceType.King && path.Squares.Take(2).Any(square => { var(point, piece) = square; return(markings.GetMarkers <SimpleMarker>(point, MarkerType.Cover, MarkerType.Check) .Any(marker => !(marker.Type == MarkerType.Check && piece.Type == marker.Piece.Type && piece.Color == marker.Piece.Color || marker.Piece.Color == path.Piece.Color))); })) { // Reject this move return; } base.Apply(markings, path); }
public MarkingFilter(Predicate <IMarker> predicate, IMarkingsProvider markings) { m_predicate = predicate; m_markings = markings; }
/// <inheritdoc /> public void Apply(IMarkingsProvider markings, Path path) { }
/// <inheritdoc /> public virtual void Apply(IMarkingsProvider markings, Path path) { m_chain.Apply(markings, path); }