Ejemplo n.º 1
0
        private bool IsMoveThreatenedKing(Piece moveCandidate, BoardCoordinate moveDestination)
        {
            var evaluator = new ThreatEvaluator(this);

            return(moveCandidate is King &&
                   evaluator.IsThreatened(moveDestination, moveCandidate.IsFirstPlayerPiece));
        }
Ejemplo n.º 2
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);
                }
            }
        }