A checkmate with a bishop and a knight against a lone king is delivered in the corner that can be covered by a bishop of the attacking side. For that reason a program ought to use a separate piece-square table for the position of the opponent king in order to drive it to the correct corner. Draw cases due to tactical loss of one of the pieces [1] or the stalemate trap are left to the search routine.
Corner-Distance
Alternatively, following Bit-twiddling determines the Manhattan-Distance to the closest corner square of the bishop square color, which might be used as a bonus for the lonesome king. First, the color of the bishop square is determined by a multiplication based on 9, to find whether its file and rank sum is odd or even. It is done that way, that an odd sum results in the sign-bit set, to build a mask by shifting arithmetically right and to conditionally flip the file of the king square, so that squares 0 and 63 become the relevant corner squares. The king's Corner Manhattan-distance is then simply the sum of its rank and file indices, if it exceeds 7 the difference to 14 is taken to force the symmetry, mirrored along the diagonal or anti-diagonal.
/**
* manhattanDistance2ClosestCornerOfBishopSquareColor
* for KBNK purpose
* @author Gerd Isenberg
* @param b bishop square (to determine its square color)
* @param k opponent king square (0..63)
* @return manhattanDistance to the closest corner square
* of the bishop square color
*/int manhattanDistance2ClosestCornerOfBishopSquareColor(int b, int k){
b =-1879048192*b >>31;// 0 | -1 to mirror
k =(k>>3)+((k^b)&7);// rank + (mirrored) file
k =(15*(k>>3)^k)-(k>>3);// if (k > 7) k = 14 - kreturn k;}
Table of Contents
A checkmate with a bishop and a knight against a lone king is delivered in the corner that can be covered by a bishop of the attacking side. For that reason a program ought to use a separate piece-square table for the position of the opponent king in order to drive it to the correct corner. Draw cases due to tactical loss of one of the pieces [1] or the stalemate trap are left to the search routine.
Corner-Distance
Alternatively, following Bit-twiddling determines the Manhattan-Distance to the closest corner square of the bishop square color, which might be used as a bonus for the lonesome king. First, the color of the bishop square is determined by a multiplication based on 9, to find whether its file and rank sum is odd or even. It is done that way, that an odd sum results in the sign-bit set, to build a mask by shifting arithmetically right and to conditionally flip the file of the king square, so that squares 0 and 63 become the relevant corner squares. The king's Corner Manhattan-distance is then simply the sum of its rank and file indices, if it exceeds 7 the difference to 14 is taken to force the symmetry, mirrored along the diagonal or anti-diagonal.which results in following x86 Assembly:
See also
Publications
Forum Posts
Re: How to get chess program to solve KBN mate? by David John Blackman, rgcc, September 18, 1997 » KnightCap
External links
References
What links here?
Up one Level