Beispiel #1
0
        private bool IsBlocked(BoardCoordinate origin, BoardCoordinate destination)
        {
            var checker         = new PathMaker(origin, destination);
            var spacesAlongPath = checker.GetPathToDestination();
            var lastSpace       = spacesAlongPath.LastOrDefault();

            return(spacesAlongPath.Any(space => DoesFriendlyPieceExistAt(origin, space)) || spacesAlongPath.Any(space => DoesPieceExistAt(space) && !space.Equals(lastSpace)));
        }
        private IEnumerable<BoardCoordinate> GetCastleMoveIfAvailable(BoardCoordinate rookStart, BoardCoordinate moveIfSuccess)
        {
            var piece = _board.GetPiece(rookStart);

            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 isBlocked = spacesBetweenKingAndRook.Any(bc => _board.GetPiece(bc) != null);

            if (piece != null && !piece.HasMoved && !isBlocked)
                yield return moveIfSuccess;
        }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
 private bool IsBlocked(BoardCoordinate origin, BoardCoordinate destination)
 {
     var checker = new PathMaker(origin, destination);
     var spacesAlongPath = checker.GetPathToDestination();
     var lastSpace = spacesAlongPath.LastOrDefault();
     return spacesAlongPath.Any(space => DoesFriendlyPieceExistAt(origin, space)) || spacesAlongPath.Any(space => DoesPieceExistAt(space) && !space.Equals(lastSpace));
 }