The CTBX(n) macro produces (1 << N)
Code: Select all
// Chess man
typedef enum
{
CTManNil = -1,
CTManWhitePawn,
CTManWhiteKnight,
CTManWhiteBishop,
CTManWhiteRook,
CTManWhiteQueen,
CTManWhiteKing,
CTManBlackPawn,
CTManBlackKnight,
CTManBlackBishop,
CTManBlackRook,
CTManBlackQueen,
CTManBlackKing,
CTManVacant,
CTManExtra
} CTMan;
#define CTManLen (CTManExtra + 1)
#define CTManRCLen (CTManBlackKing + 1)
#define CTForEachMan(theIndex) CTIndexLoop(theIndex, CTManLen)
#define CTForEachManRC(theIndex) CTIndexLoop(theIndex, CTManRCLen)
#define CTMaskManWhite 0x003f
#define CTMaskManBlack 0x0fc0
inline bool IsNil(const CTMan theMan) {return theMan < 0;}
inline bool IsNotNil(const CTMan theMan) {return theMan >= 0;}
inline bool IsRC(const CTMan theMan)
{
return theMan < CTManRCLen;
}
inline bool IsValidMan(const CTMan theMan)
{
return (theMan >= 0) && (theMan < CTManLen);
}
inline bool IsValidManRC(const CTMan theMan)
{
return (theMan >= 0) && (theMan < CTManRCLen);
}
inline bool IsWhite(const CTMan theMan)
{
return CTMaskManWhite & CTBX(theMan);
}
inline bool IsBlack(const CTMan theMan)
{
return CTMaskManBlack & CTBX(theMan);
}
inline CTColor MapToColorRC(const CTMan theMan)
{
return (theMan < CTManBlackPawn) ? CTColorWhite : CTColorBlack;
}
inline CTPiece MapToPieceRC(const CTMan theMan)
{
return (CTPiece)
((theMan < CTManBlackPawn) ?
(int) theMan : (int) (theMan - CTManBlackPawn));
}
inline bool IsPawn(const CTMan theMan)
{
return 0x0041 & CTBX(theMan);
}
inline bool IsKnight(const CTMan theMan)
{
return 0x0082 & CTBX(theMan);
}
inline bool IsBishop(const CTMan theMan)
{
return 0x0104 & CTBX(theMan);
}
inline bool IsRook(const CTMan theMan)
{
return 0x0208 & CTBX(theMan);
}
inline bool IsQueen(const CTMan theMan)
{
return 0x0410 & CTBX(theMan);
}
inline bool IsKing(const CTMan theMan)
{
return 0x0820 & CTBX(theMan);
}
inline bool IsVacant(const CTMan theMan)
{
return theMan == CTManVacant;
}
inline bool IsNotVacant(const CTMan theMan)
{
return theMan != CTManVacant;
}
inline bool IsWhitePawn(const CTMan theMan)
{
return theMan == CTManWhitePawn;
}
inline bool IsBlackPawn(const CTMan theMan)
{
return theMan == CTManBlackPawn;
}
inline bool IsWhiteKnight(const CTMan theMan)
{
return theMan == CTManWhiteKnight;
}
inline bool IsBlackKnight(const CTMan theMan)
{
return theMan == CTManBlackKnight;
}
inline bool IsWhiteBishop(const CTMan theMan)
{
return theMan == CTManWhiteBishop;
}
inline bool IsBlackBishop(const CTMan theMan)
{
return theMan == CTManBlackBishop;
}
inline bool IsWhiteRook(const CTMan theMan)
{
return theMan == CTManWhiteRook;
}
inline bool IsBlackRook(const CTMan theMan)
{
return theMan == CTManBlackRook;
}
inline bool IsWhiteQueen(const CTMan theMan)
{
return theMan == CTManWhiteQueen;
}
inline bool IsBlackQueen(const CTMan theMan)
{
return theMan == CTManBlackQueen;
}
inline bool IsWhiteKing(const CTMan theMan)
{
return theMan == CTManWhiteKing;
}
inline bool IsBlackKing(const CTMan theMan)
{
return theMan == CTManBlackKing;
}
inline bool IsStep(const CTMan theMan)
{
return 0x08e3 & CTBX(theMan);
}
inline bool IsSweep(const CTMan theMan)
{
return 0x071c & CTBX(theMan);
}
inline bool IsMajor(const CTMan theMan)
{
return 0x0618 & CTBX(theMan);
}
inline bool IsMinor(const CTMan theMan)
{
return 0x0186 & CTBX(theMan);
}
inline bool IsQRBNP(const CTMan theMan)
{
return 0x07df & CTBX(theMan);
}
inline bool IsQRBN(const CTMan theMan)
{
return 0x079e & CTBX(theMan);
}
inline bool IsQRP(const CTMan theMan)
{
return 0x0659 & CTBX(theMan);
}
inline bool IsWhiteKQR(const CTMan theMan)
{
return 0x0038 & CTBX(theMan);
}
inline bool IsBlackKQR(const CTMan theMan)
{
return 0x0e00 & CTBX(theMan);
}
inline bool IsWhiteKQB(const CTMan theMan)
{
return 0x0034 & CTBX(theMan);
}
inline bool IsBlackKQB(const CTMan theMan)
{
return 0x0d00 & CTBX(theMan);
}
inline bool IsWhiteQRBNP(const CTMan theMan)
{
return 0x001f & CTBX(theMan);
}
inline bool IsBlackQRBNP(const CTMan theMan)
{
return 0x07c0 & CTBX(theMan);
}
inline bool IsWhiteQRP(const CTMan theMan)
{
return 0x0019 & CTBX(theMan);
}
inline bool IsBlackQRP(const CTMan theMan)
{
return 0x0640 & CTBX(theMan);
}
inline bool IsWhiteQR(const CTMan theMan)
{
return 0x0018 & CTBX(theMan);
}
inline bool IsBlackQR(const CTMan theMan)
{
return 0x0600 & CTBX(theMan);
}
inline bool IsWhiteQB(const CTMan theMan)
{
return 0x0014 & CTBX(theMan);
}
inline bool IsBlackQB(const CTMan theMan)
{
return 0x0500 & CTBX(theMan);
}
inline bool IsWhiteBN(const CTMan theMan)
{
return 0x0006 & CTBX(theMan);
}
inline bool IsBlackBN(const CTMan theMan)
{
return 0x0180 & CTBX(theMan);
}
inline char LCCharFromMan(const CTMan theMan)
{
return "pnbrqkpnbrqk ?"[theMan];
}
inline char UCCharFromMan(const CTMan theMan)
{
return "PNBRQKPNBRQK ?"[theMan];
}
inline char MPDCharFromMan(const CTMan theMan)
{
return "PNBRQKpnbrqk ?"[theMan];
}