예제 #1
0
        private bool CanBlockAttack(GameModel game, IChessPiece target, IChessPiece attacker)
        {
            var positionsToBlock = attacker.GetPathToDestination(target.Position);

            if (positionsToBlock is null)
            {
                return(false);
            }

            foreach (var positionToBlock in positionsToBlock)
            {
                foreach (var chessPiece in game.MovingPlayer.Pieces)
                {
                    var move = new Move(chessPiece.Position, positionToBlock);

                    if (!(chessPiece is King) &&
                        gameValidationService.ValidateMove(game, move) != null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }