H. G. Muller wrote on Mon, Nov 14, 2022 09:01 PM UTC:
I found a loophole for easily allowing the forbidden trades as checkmate evasion, in the Diagram! There already was a parameter tradingThreshold, which served to implement Chu Shogi's exemption of 'bridge captures' from the Lion-trading rules: when you gain more than this threshold in the exchange, it is no longer forbidden to trade the protected piece. This can conveniently be used for suspending the anti-trade rule, by setting it to a large negative value. So in the mate-handling code (executed when after all moves have been searched bestScore is still at -15000) I added
if(exemption) {
var h = threshold;
threshold = -15000; exemption = 0;
bestScore = AlphaBeta(stm, alpha, beta, eval, last, preLast, depth, borrow, ply); // redo without trade ban
if(ply == 0) bestNr = bestScore; // needed because in the root we return the best move instead of the score
threshold = h; exemption = 1;
} else ... // normal mate handling
This redoes the search of the node without trade ban (with a cleared flag exemption set through a new mateExemption parameter to prevent infinite recursion).
That does the trick: If I set up a mate through a7-a5, Ke8-a4, Gd8-c6, d2-d3, switch on AI, and then Gd1-c4, it will play Gc6xc4. If I set up a normal favorable trade, like Rh8-h6, Ra1-a6, Gd1-f6, switch on AI, and then Gd8-h6, it refrains from Gf6xh6, even though that would gain it a Rook.
I found a loophole for easily allowing the forbidden trades as checkmate evasion, in the Diagram! There already was a parameter tradingThreshold, which served to implement Chu Shogi's exemption of 'bridge captures' from the Lion-trading rules: when you gain more than this threshold in the exchange, it is no longer forbidden to trade the protected piece. This can conveniently be used for suspending the anti-trade rule, by setting it to a large negative value. So in the mate-handling code (executed when after all moves have been searched bestScore is still at -15000) I added
This redoes the search of the node without trade ban (with a cleared flag exemption set through a new mateExemption parameter to prevent infinite recursion).
That does the trick: If I set up a mate through a7-a5, Ke8-a4, Gd8-c6, d2-d3, switch on AI, and then Gd1-c4, it will play Gc6xc4. If I set up a normal favorable trade, like Rh8-h6, Ra1-a6, Gd1-f6, switch on AI, and then Gd8-h6, it refrains from Gf6xh6, even though that would gain it a Rook.