Exemple #1
0
        public (bool result, LocatedItem <ChessPieceEntity> attacker) IsLocationUnderCheck(IBoardState <ChessPieceEntity> boardState,
                                                                                           BoardLocation location, Colours defender)
        {
            var attackPaths = _pathFinder.Attacking(location, defender);

            var straightAttackPieces = new[] { ChessPieceName.Rook, ChessPieceName.Queen };
            var diagonalAttackPieces = new[] { ChessPieceName.Bishop, ChessPieceName.Queen };
            var knightAttackPieces   = new[] { ChessPieceName.Knight };
            var pawnAttackPieces     = new[] { ChessPieceName.Pawn };

            var attackPath = PathsContainsAttack(attackPaths.Straight, straightAttackPieces, defender.Enemy(), boardState);

            if (attackPath.result)
            {
                return(true, attackPath.attacker);
            }

            attackPath = PathsContainsAttack(attackPaths.Diagonal, diagonalAttackPieces, defender.Enemy(), boardState);
            if (attackPath.result)
            {
                return(true, attackPath.attacker);
            }

            attackPath = PathsContainsAttack(attackPaths.Knight, knightAttackPieces, defender.Enemy(), boardState);
            if (attackPath.result)
            {
                return(true, attackPath.attacker);
            }

            attackPath = PathsContainsAttack(attackPaths.Pawns, pawnAttackPieces, defender.Enemy(), boardState);
            if (attackPath.result)
            {
                return(true, attackPath.attacker);
            }

            return(false, null);
        }