protected bool IsCastlingPossible(TypeOfCastling typeOfCastling, Position position, ChessboardModel chessboard) { int rookXPosition; int[] emptyFieldXPositions, attackFieldXPositions; switch (typeOfCastling) { case TypeOfCastling.Long: rookXPosition = 0; emptyFieldXPositions = new int[] { 1, 2, 3 }; attackFieldXPositions = new int[] { 2, 3, 4 }; break; case TypeOfCastling.Short: rookXPosition = 7; emptyFieldXPositions = new int[] { 5, 6 }; attackFieldXPositions = new int[] { 4, 5, 6 }; break; default: throw new ApplicationException("unexpected argument"); } return(IsRookExist(rookXPosition, rookYPosition: position.Y, chessboard) && AreCastlingFieldsEmpty(emptyFieldXPositions, position, chessboard) && AreCastlingFieldsNotAttacking(attackFieldXPositions, position, chessboard)); }
public ICheckStrategy CreateKingStrategyWithCastlingDecorator(TypeOfCastling typeOfCastling) { var checkStrategy = new KingCheckStrategy(); var firstMovieDecorator = new FirstMovieDecorator(); var shortCastlingDecorator = new ShortCastlingDecorator(); var longCastlingDecorator = new LongCastlingDecorator(); firstMovieDecorator.Component = checkStrategy; switch (typeOfCastling) { case TypeOfCastling.Long: longCastlingDecorator.Component = firstMovieDecorator; return(longCastlingDecorator); case TypeOfCastling.Short: shortCastlingDecorator.Component = firstMovieDecorator; return(shortCastlingDecorator); case TypeOfCastling.Both: longCastlingDecorator.Component = firstMovieDecorator; shortCastlingDecorator.Component = longCastlingDecorator; return(shortCastlingDecorator); default: throw new ApplicationException("unexpected argument"); } }