strict practice "mate in" requirement - closes #2657
parent
1e821189c4
commit
1fa898255b
|
@ -9,6 +9,13 @@ function isWinning(node, goalCp, color) {
|
|||
var cp = node.ceval.mate > 0 ? 99999 : (node.ceval.mate < 0 ? -99999 : node.ceval.cp);
|
||||
return color === 'white' ? cp >= goalCp : cp <= goalCp;
|
||||
}
|
||||
// returns null if not deep enough to know
|
||||
function myMateIn(node, color) {
|
||||
if (!hasSolidEval(node)) return null;
|
||||
if (!node.ceval.mate) return false;
|
||||
var mateIn = node.ceval.mate * (color === 'white' ? 1 : -1);
|
||||
return mateIn > 0 ? mateIn : false;
|
||||
}
|
||||
|
||||
function hasSolidEval(node) {
|
||||
return node.ceval && node.ceval.depth >= 16;
|
||||
|
@ -17,9 +24,11 @@ function hasSolidEval(node) {
|
|||
function isMate(root) {
|
||||
return root.gameOver() === 'checkmate';
|
||||
}
|
||||
|
||||
function isMyMate(root) {
|
||||
return isMate(root) && root.turnColor() !== root.bottomColor();
|
||||
}
|
||||
|
||||
function isTheirMate(root) {
|
||||
return isMate(root) && root.turnColor() === root.bottomColor();
|
||||
}
|
||||
|
@ -41,15 +50,17 @@ module.exports = function(root, goal, nbMoves) {
|
|||
if (isDrawish(node) === false) return false;
|
||||
if (nbMoves > goal.moves) return false;
|
||||
if (root.gameOver() === 'draw') return true;
|
||||
if (nbMoves === goal.moves) return isDrawish(node);
|
||||
if (nbMoves >= goal.moves) return isDrawish(node);
|
||||
break;
|
||||
case 'evalIn':
|
||||
if (nbMoves === goal.moves) return isWinning(node, goal.cp, root.bottomColor());
|
||||
if (nbMoves >= goal.moves) return isWinning(node, goal.cp, root.bottomColor());
|
||||
break;
|
||||
case 'mateIn':
|
||||
if (nbMoves > goal.moves) return false;
|
||||
if (isMyMate(root)) return true;
|
||||
if (nbMoves === goal.moves) return false;
|
||||
var mateIn = myMateIn(node, root.bottomColor());
|
||||
if (mateIn === null) return null;
|
||||
if (!mateIn || mateIn + nbMoves > goal.moves) return false;
|
||||
break;
|
||||
case 'promotion':
|
||||
if (!node.uci[4]) return null;
|
||||
|
|
Loading…
Reference in New Issue