Just train it to make it win. Then, anytime it is a bit in front, perform suboptimal moves, until things are even (those engines typically have a score on whether they are in front or not).
Not sure that would work in an end game though. If you are behind and make a good move, you accidentally win. If you are technically ahead and make a bad move, you probably lose.
If you can get reliably to an end game with only a king and a one or maybe two pieces left on each side, then maybe it can just be hand-scripted and bolted onto what you're proposing, but I'm not sure your proposal would consistently get it there.
If you can get reliably to an end game with only a king and a one or maybe two pieces left on each side, then maybe it can just be hand-scripted and bolted onto what you're proposing, but I'm not sure your proposal would consistently get it there.