Exemplo n.º 1
0
        private void AddThreats(
            Board board,
            Player player,
            BoardLocation playerKingLocation,
            BoardLocation opposingPieceBoardLocation,
            ThreatMatrix threatMatrix)
        {
            var chessPiece = board[opposingPieceBoardLocation];

            switch (chessPiece)
            {
            case ChessPiece.BlackPawn:
            case ChessPiece.WhitePawn:
                AddPawnThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                break;

            case ChessPiece.BlackRook:
            case ChessPiece.WhiteRook:
                AddRookThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                break;

            case ChessPiece.BlackKnight:
            case ChessPiece.WhiteKnight:
                AddKnightThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                break;

            case ChessPiece.BlackBishop:
            case ChessPiece.WhiteBishop:
                AddBishopThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                break;

            case ChessPiece.BlackQueen:
            case ChessPiece.WhiteQueen:
                //queen is rook and bishop so we can cheat it
                AddRookThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                AddBishopThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                break;

            case ChessPiece.BlackKing:
            case ChessPiece.WhiteKing:
                AddKingThreats(board, player, playerKingLocation, opposingPieceBoardLocation, threatMatrix);
                break;

            default:
                throw new Exception($"Unexpected chessPiece value {opposingPieceBoardLocation.ToString()}");
            }
        }