From 22dd9bcd6ae74b6206a606e617286f4277eb801c Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 23 Aug 2010 12:39:07 +0200 Subject: [PATCH] Trivial-draws recognition improved in Xiangqi Now based on a routine "SufficientDefence". If both have it, it is draw. --- backend.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-) diff --git a/backend.c b/backend.c index 31d74e2..3c21f9d 100644 --- a/backend.c +++ b/backend.c @@ -6595,8 +6595,9 @@ Count(Board board, int pCnt[], int *nW, int *nB, int *wStale, int *bStale, int * for(p=WhitePawn; p<=EmptySquare; p++) pCnt[p] = 0; for(r=0; r 2) return FALSE; // no trivial draws with more than 1 major + if(myPawns == 2 && nMine == 3) // KPP + return majorDefense || pCnt[BlackFerz-side] + pCnt[BlackAlfil-side] >= 3; + if(myPawns == 1 && nMine == 2) // KP + return majorDefense || pCnt[BlackFerz-side] + pCnt[BlackAlfil-side] + pCnt[BlackPawn-side] >= 1; + if(myPawns == 1 && nMine == 3 && pCnt[WhiteKnight+side]) // KHP + return majorDefense || pCnt[BlackFerz-side] + pCnt[BlackAlfil-side]*2 >= 5; + if(myPawns) return FALSE; + if(pCnt[WhiteRook+side]) + return pCnt[BlackRook-side] || + pCnt[BlackCannon-side] && (pCnt[BlackFerz-side] >= 2 || pCnt[BlackAlfil-side] >= 2) || + pCnt[BlackKnight-side] && pCnt[BlackFerz-side] + pCnt[BlackAlfil-side] > 2 || + pCnt[BlackFerz-side] + pCnt[BlackAlfil-side] >= 4; + if(pCnt[WhiteCannon+side]) { + if(pCnt[WhiteFerz+side] + myPawns == 0) return TRUE; // Cannon needs platform + return majorDefense || pCnt[BlackAlfil-side] >= 2; + } + if(pCnt[WhiteKnight+side]) + return majorDefense || pCnt[BlackFerz-side] >= 2 || pCnt[BlackAlfil-side] + pCnt[BlackPawn-side] >= 1; + return FALSE; +} + +int MatingPotential(int pCnt[], int side, int nMine, int nHis, int stale, int bisColor) { VariantClass v = gameInfo.variant; @@ -6798,12 +6828,14 @@ Adjudicate(ChessProgramState *cps) } /* Then some trivial draws (only adjudicate, cannot be claimed) */ - if(nrW + nrB == 4 && + if(gameInfo.variant == VariantXiangqi ? + SufficientDefence(nr, WhitePawn, nrW, nrB) && SufficientDefence(nr, BlackPawn, nrB, nrW) + : nrW + nrB == 4 && ( nr[WhiteRook] == 1 && nr[BlackRook] == 1 /* KRKR */ || nr[WhiteQueen] && nr[BlackQueen]==1 /* KQKQ */ || nr[WhiteKnight]==2 || nr[BlackKnight]==2 /* KNNK */ || nr[WhiteKnight]+nr[WhiteBishop] == 1 && nr[BlackKnight]+nr[BlackBishop] == 1 /* KBKN, KBKB, KNKN */ - ) ) { + ) ) { if(--moveCount < 0 && appData.trivialDraws && canAdjudicate) { /* if the first 3 moves do not show a tactical win, declare draw */ if(engineOpponent) { -- 1.7.0.4