private IEnumerable <BoardCoordinate> EvaluateRowForCastling(int row) { var queenCastleOption = GetCastleMoveIfAvailable(BoardCoordinate.For(QueensRookColumn, row), BoardCoordinate.For(QueenCastleColumn, row)); var kingCastleOption = GetCastleMoveIfAvailable(BoardCoordinate.For(KingRookColumn, row), BoardCoordinate.For(KingCastleColumn, row)); return(queenCastleOption.Union(kingCastleOption)); }
private IEnumerable <BoardCoordinate> GetDiagonalPathSpaces() { var absoluteDistance = Math.Abs(_origin.X - _destination.X); var xDirection = (_destination.X - _origin.X) / absoluteDistance; var yDirection = (_destination.Y - _origin.Y) / absoluteDistance; return(Enumerable.Range(1, absoluteDistance).Select(i => BoardCoordinate.For(_origin.X + i * xDirection, _origin.Y + i * yDirection))); }
public bool IsThreatened(BoardCoordinate victim, bool isFirstPlayerAttacking) { var numbers = Enumerable.Range(1, _board.Size); var coordinates = numbers.SelectMany(x => numbers, (x, y) => BoardCoordinate.For(x, y)); return(coordinates.Any(c => DoesSquareAttack(c, victim, isFirstPlayerAttacking))); }
private void SetEnPassantIfCandidatePawnsArePresent(BoardCoordinate destination) { var leftTarget = BoardCoordinate.For(destination.X - 1, destination.Y); var rightTarget = BoardCoordinate.For(destination.X + 1, destination.Y); SetEnPassantIfPawnExistsAtTarget(destination, leftTarget); SetEnPassantIfPawnExistsAtTarget(destination, rightTarget); }
private IEnumerable <BoardCoordinate> GetVerticalPathSpaces() { if (_origin.Y < _destination.Y) { var yCoordinatesToCheck = Enumerable.Range(_origin.Y + 1, _destination.Y - _origin.Y); return(yCoordinatesToCheck.Select(y => BoardCoordinate.For(_origin.X, y))); } else { var yCoordinatesToCheck = Enumerable.Range(_destination.Y, _origin.Y - _destination.Y).Reverse(); return(yCoordinatesToCheck.Select(y => BoardCoordinate.For(_origin.X, y))); } }
private IEnumerable <BoardCoordinate> GetHorizontalPathSpaces() { if (_origin.X < _destination.X) { var xCoordinatesToCheck = Enumerable.Range(_origin.X + 1, _destination.X - _origin.X); return(xCoordinatesToCheck.Select(x => BoardCoordinate.For(x, _origin.Y))); } else if (_origin.X > _destination.X) { var xCoordinatesToCheck = Enumerable.Range(_destination.X, _origin.X - _destination.X).Reverse(); return(xCoordinatesToCheck.Select(x => BoardCoordinate.For(x, _origin.Y))); } return(Enumerable.Empty <BoardCoordinate>()); }
private IEnumerable <BoardCoordinate> GetCastleMoveIfAvailable(BoardCoordinate rookStart, BoardCoordinate moveIfSuccess) { var piece = _board.GetPiece(rookStart); if (piece != null) { var kingCoordinate = BoardCoordinate.For(KingColumn, rookStart.Y); var pathMaker = new PathMaker(kingCoordinate, rookStart); var spacesBetweenKingAndRook = pathMaker.GetPathToDestination().Where(bc => bc.X != rookStart.X && bc.X != KingColumn); var threatEvaluator = new ThreatEvaluator(_board); var wouldKingBeThreatened = spacesBetweenKingAndRook.Any(bc => threatEvaluator.IsThreatened(bc, piece.IsFirstPlayerPiece)); var isBlocked = spacesBetweenKingAndRook.Any(bc => _board.GetPiece(bc) != null); if (!piece.HasMoved && !isBlocked && !wouldKingBeThreatened) { yield return(moveIfSuccess); } } }
public override bool IsNonCaptureAllowed(BoardCoordinate origin, BoardCoordinate destination) { return(IsVerticalMoveBy(1, origin, destination) || IsSpecialFirstPawnMoveAllowed(origin, destination) || (CanPerformEnPassantOn(BoardCoordinate.For(destination.X, origin.Y)))); }