// CachedPosition.Data Bits // 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 // 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // To Horizon |Best From |Best To |BMP |Score |SP |Last Accessed // Best From = Best Move From (one extra bit for illegal square) // Best To = Best Move To (one extra bit for illegal square) // BMP = Best Move Promoted Piece // SP = Score Precision static CachedPositionData() { // Create bit shifts and masks. _toHorizonShift = 58; _toHorizonMask = Bitwise.CreateULongMask(58, 63); _toHorizonUnmask = Bitwise.CreateULongUnmask(58, 63); _bestMoveFromShift = 51; _bestMoveFromMask = Bitwise.CreateULongMask(51, 57); _bestMoveFromUnmask = Bitwise.CreateULongUnmask(51, 57); _bestMoveToShift = 44; _bestMoveToMask = Bitwise.CreateULongMask(44, 50); _bestMoveToUnmask = Bitwise.CreateULongUnmask(44, 50); _bestMovePromotedPieceShift = 40; _bestMovePromotedPieceMask = Bitwise.CreateULongMask(40, 43); _bestMovePromotedPieceUnmask = Bitwise.CreateULongUnmask(40, 43); _scoreShift = 10; _scoreMask = Bitwise.CreateULongMask(10, 39); _scoreUnmask = Bitwise.CreateULongUnmask(10, 39); _scorePrecisionShift = 8; _scorePrecisionMask = Bitwise.CreateULongMask(8, 9); _scorePrecisionUnmask = Bitwise.CreateULongUnmask(8, 9); _lastAccessedMask = Bitwise.CreateULongMask(0, 7); _lastAccessedUnmask = Bitwise.CreateULongUnmask(0, 7); }
// Move Bits // Higher priority moves have higher ulong value. // 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 // 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // B|CapV |CapA |Promo |Kil|History |!|O|K|E|2|P|C|Q|From |To // 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 // B = Best Move // CapV = Capture Victim // CapA = Capture Attacker (inverted) // Promo = Promoted Piece // Kil = Killer Move // ! = Played // O = Castling // K = King Move // E = En Passant Capture // 2 = Double Pawn Move // P = Pawn Move // C = Check // Q = Quiet (not capture, pawn promotion, castling, or check) // From = From (one extra bit for illegal square) // To = To (one extra bit for illegal square) static Move() { // Create bit masks and shifts. _bestShift = 63; _bestMask = Bitwise.CreateULongMask(63); _bestUnmask = Bitwise.CreateULongUnmask(63); _captureVictimShift = 59; _captureVictimMask = Bitwise.CreateULongMask(59, 62); _captureVictimUnmask = Bitwise.CreateULongUnmask(59, 62); _captureAttackerShift = 55; _captureAttackerMask = Bitwise.CreateULongMask(55, 58); _captureAttackerUnmask = Bitwise.CreateULongUnmask(55, 58); _promotedPieceShift = 51; _promotedPieceMask = Bitwise.CreateULongMask(51, 54); _promotedPieceUnmask = Bitwise.CreateULongUnmask(51, 54); _killerShift = 49; _killerMask = Bitwise.CreateULongMask(49, 50); _killerUnmask = Bitwise.CreateULongUnmask(49, 50); _historyShift = 22; _historyMask = Bitwise.CreateULongMask(22, 48); _historyUnmask = Bitwise.CreateULongUnmask(22, 48); _playedShift = 21; _playedMask = Bitwise.CreateULongMask(21); _playedUnmask = Bitwise.CreateULongUnmask(21); _castlingShift = 20; _castlingMask = Bitwise.CreateULongMask(20); _castlingUnmask = Bitwise.CreateULongUnmask(20); _kingMoveShift = 19; _kingMoveMask = Bitwise.CreateULongMask(19); _kingMoveUnmask = Bitwise.CreateULongUnmask(19); _enPassantShift = 18; _enPassantMask = Bitwise.CreateULongMask(18); _enPassantUnmask = Bitwise.CreateULongUnmask(18); _doublePawnMoveShift = 17; _doublePawnMoveMask = Bitwise.CreateULongMask(17); _doublePawnMoveUnmask = Bitwise.CreateULongUnmask(17); _pawnMoveShift = 16; _pawnMoveMask = Bitwise.CreateULongMask(16); _pawnMoveUnmask = Bitwise.CreateULongUnmask(16); _checkShift = 15; _checkMask = Bitwise.CreateULongMask(15); _checkUnmask = Bitwise.CreateULongUnmask(15); _quietShift = 14; _quietMask = Bitwise.CreateULongMask(14); _quietUnmask = Bitwise.CreateULongUnmask(14); _fromShift = 7; _fromMask = Bitwise.CreateULongMask(7, 13); _fromUnmask = Bitwise.CreateULongUnmask(7, 13); _toMask = Bitwise.CreateULongMask(0, 6); _toUnmask = Bitwise.CreateULongUnmask(0, 6); // Set null move. Null = 0; SetIsBest(ref Null, false); SetCaptureVictim(ref Null, Piece.None); SetCaptureAttacker(ref Null, Piece.None); SetPromotedPiece(ref Null, Piece.None); SetKiller(ref Null, 0); SetHistory(ref Null, 0); SetPlayed(ref Null, false); SetIsCastling(ref Null, false); SetIsKingMove(ref Null, false); SetIsEnPassantCapture(ref Null, false); SetIsDoublePawnMove(ref Null, false); SetIsPawnMove(ref Null, false); SetIsCheck(ref Null, false); SetIsQuiet(ref Null, false); SetFrom(ref Null, Square.Illegal); SetTo(ref Null, Square.Illegal); }