If an AI is sure it is going to lose, what can it do to make the game fun for the player?

For context i am contributing to a sequential turn based strategy game. I have an idea how to improve it but i feel i need some input to help me evaluate and improve it. We currently have a really dumb AI that just follows a rough set of rules each turn. I’m considering to upgrade it to a basic search based AI to not be guaranteed to win every time i play it.

There are many reason why an AI could be behind the curve. These include that is wasn’t able to grow it’s economy well due to bad luck with map generation, that it’s economy was disrupted early by an enemy raid while the defending army was out of reach, that the starter army was defeated early and resources had to be invested to replace it instead of economic upgrades or more importantly there being a big awesome deciding battle with all units involved and it lost. A search based AI will be able to know when it is obvious that it is growing slower than it should, can’t recover and it is now impossible to win due to runaway success. Such a runaway success is often boring to play especially if it happened 3 times in a row.

Assume there is no meta game where multiple players can gang up on the strongest one. I am open to nudge the game rules in the AIs favor if this happens. However rubber banding can give the player the impression that they are punished for playing well, the AI drags out a game into an almost stalemate or even wins unfairly.

The problem i’m trying to solve is not that the AI is loosing but that the AI rolling over and dying is not fun or interesting.

It is even worse. If the player is sufficiently good he will experience that every time.

In some theories of literature after the conclusion seems forgone and the tension is falling a new small conflict that is relevant enough or something else that justifies further elaboration and excitement. enter image description here

My idea is to have a library of endgame scenarios, a handful of which end up with player loosing unless he plays really well, most pose a small challenge that the player is entirely able to deal with and some are a "i role over, just kill me already, please".

Are you aware of anyone trying something like this before? If someone tried this in a strategy game or even outside of strategy games before i would like to learn from them.

Can you spot some obvious problems with this idea? I already considered the AI misjudging the impossibility of wining. However i might be to enamored with my idea to spot different problems.

How can i make sure that this still feels fair? It is easy for the AI to get some extra resources however if a player is loosing i am afraid that he would feel cheapened if he got some extra money and units.

How i help the player having fun or at-least variety when they are losing? I really have no ideas for this.