static void DES(char* Out, char* In, PSubKey pSubKey, int Type) { int i; static char M[64], tmp[32], *Li=&M[0], *Ri=&M[32]; ByteToBit(M, In, 64); Transform(M, M, IP_Table, 64); if (Type==ENCRYPT) { for (i=0; i<16; ++i) { memcpy(tmp, Ri, 32); F_func(Ri, (*pSubKey)[i]); Xor(Ri, Li, 32); memcpy(Li, tmp, 32); } } else { for (i=15; i>=0; --i) { memcpy(tmp, Li, 32); F_func(Li, (*pSubKey)[i]); Xor(Li, Ri, 32); memcpy(Ri, tmp, 32); } } Transform(M, M, IPR_Table, 64); BitToByte(Out, M, 64); }
void BulkRound::CreateDescriptor(const QByteArray &data) { int length = data.size(); Hash hashalgo; QByteArray xor_message(length, 0); QVector<QByteArray> hashes; int my_idx = GetGroup().GetIndex(GetLocalId()); foreach(const PublicIdentity &gc, GetGroup().GetRoster()) { QByteArray seed = _anon_dh.GetSharedSecret(gc.GetDhKey()); if(hashes.size() == my_idx) { hashes.append(QByteArray()); continue; } QByteArray msg(length, 0); CryptoRandom(seed).GenerateBlock(msg); hashes.append(hashalgo.ComputeHash(msg)); Xor(xor_message, xor_message, msg); } QByteArray my_xor_message = QByteArray(length, 0); Xor(my_xor_message, xor_message, data); SetMyXorMessage(my_xor_message); hashes[my_idx] = hashalgo.ComputeHash(my_xor_message); QByteArray hash = hashalgo.ComputeHash(data); Descriptor descriptor(length, _anon_dh.GetPublicComponent(), hashes, hash); SetMyDescriptor(descriptor); }
bool PolyChecker::IntersectProp(const DPoint2 &a, const DPoint2 &b, const DPoint2 &c, const DPoint2 &d) { if (Collinear(a, b, c) || Collinear(a, b, d) || Collinear(c, d, a) || Collinear(c, d, b)) return false; return Xor(Left(a, b, c), Left(a, b, d)) && Xor(Left(c, d, a), Left(c, d, b)); }
/* proper intersection test: lines ab and cd */ bool prop_intersect(point2D a, point2D b, point2D c, point2D d) { if(collinear(a,b,c) || collinear(a,b,d) || collinear(c,d,a) || collinear(c,d,b)) return false; return Xor( left(a,b,c) == 1, left(a,b,d) == 1 ) && Xor( left(c,d,a) == 1, left(c,d,b) == 1 ); }
void ac::ReverseSubFilterXor(cv::Mat &frame) { if(subfilter == -1 || ac::draw_strings[subfilter] == "ReverseSubFilterXor") return; cv::Mat copy1 = frame.clone(), copy2 = frame.clone(); Reverse(copy1); CallFilter(subfilter, copy1); CallFilter(subfilter, copy2); Xor(copy1, frame); Xor(copy2, frame); AlphaBlend(copy1, copy2, frame, 0.5); }
double H(double *dK, double *dX, double *dY, Cipher *ciph) { double dF2X[32]; double dFinv2X[32]; double dTemp[32]; double dH = 1.0; for(int i = 0; i < 32; i++) dF2X[i] = dX[i]; for(int c = 0; c < 2; c++) { Xor(dF2X, dK, 32); for(int i = 0; i < 32; i+=4) Sub(dF2X+i); /**/ for(int i = 0; i < 32; i++) dTemp[i] = dF2X[i]; for(int i = 0; i < 32; i++) dF2X[ciph->per->pers[i]] = dTemp[i]; /**/ } /**/ for(int i = 0; i < 32; i++) dFinv2X[i] = dY[i]; Xor(dFinv2X, dK, 32); for(int c = 0; c < 2; c++) { for(int i = 0; i < 32; i++) dTemp[i] = dFinv2X[i]; for(int i = 0; i < 32; i++) dFinv2X[ciph->per->pers_inv[i]] = dTemp[i]; for(int i = 0; i < 32; i+=4) SubInv(dFinv2X+i); Xor(dFinv2X, dK, 32); } /**/ for(int i = 0; i < 32; i++) dH *= 1 - abs(dF2X[i] - dFinv2X[i]); return dH; }
void ac::XorReverseImageSmooth(cv::Mat &frame) { if(blend_set == false) return; cv::Mat copy1 = frame.clone(), copy2 = frame.clone(), reimage; cv::resize(blend_image, reimage, frame.size()); Xor(copy1, reimage); Reverse(reimage); Xor(copy2, reimage); pushSubFilter(filter_map["ExactImage"]); SmoothSubFilter32(copy1); popSubFilter(); AlphaBlend(copy1, copy2, frame, 0.5); MedianBlend(frame); }
void push_back(value_type value) { node_pointer temp = new node_type(value); temp->setXorPointer(tail, NULL); if (tail == NULL) { head = temp; tail = temp; } else { // 首先要找到tail 之前的那个指 XorDoubleLinkedListNode* pre = Xor(tail->getXorPointer(), NULL); tail->setXorPointer(Xor(pre, temp)); tail = temp; } }
/*--------------------------------------------------------------------- Returns true iff ab properly intersects cd: they share a point interior to both segments. The properness of the intersection is ensured by using strict leftness. ---------------------------------------------------------------------*/ bool IntersectProp( tPointi a, tPointi b, tPointi c, tPointi d ) { /* Eliminate improper cases. */ if ( Collinear(a,b,c) || Collinear(a,b,d) || Collinear(c,d,a) || Collinear(c,d,b) ) return FALSE; return Xor( Left(a,b,c), Left(a,b,d) ) && Xor( Left(c,d,a), Left(c,d,b) ); }
// 插入head之前 void push_front(value_type value) { node_pointer temp = new node_type(value); temp->setXorPointer(Xor(head, NULL)); if (head == NULL) { head = temp; tail = temp; } else { XorDoubleLinkedListNode* next = Xor(head->getXorPointer(), NULL); // 重新设置head 的 m_diff; head->setXorPointer(Xor(temp, next)); // head 指向当前节点; head = temp; } }
bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) { #if 0 wxRegion reg( x, y, width, height ); return Xor( reg ); #endif }
void ac::ImageReverseSubFilter(cv::Mat &frame) { if(blend_set == false || subfilter == -1 || ac::draw_strings[subfilter] == "ImageReverseSubFilter") return; cv::Mat reimage; cv::resize(blend_image, reimage, frame.size()); cv::Mat all_frames[3]; cv::flip(frame, all_frames[0], -1); cv::flip(frame, all_frames[1], 0); cv::flip(frame, all_frames[2], 1); cv::Mat copy1 = frame.clone(), copy2 = frame.clone(); for(int z = 0; z < copy1.rows; ++z) { for(int i = 0; i < copy1.cols; ++i){ cv::Vec3b &pixel = copy1.at<cv::Vec3b>(z, i); cv::Vec3b pix[4]; for(int j = 0; j < 3; ++j) { pix[j] = all_frames[j].at<cv::Vec3b>(z, i); } for(int j = 0; j < 3; ++j) { pixel[j] = pix[0][j] ^ pix[1][j] ^ pix[2][j] ^ pixel[j]; } } } static MatrixCollection<8> collection; Smooth(copy1, &collection); CallFilter(subfilter, reimage); Xor(reimage, copy1); AlphaBlend(reimage, copy2, frame, 0.5); DarkenFilter(frame); MedianBlend(frame); }
QByteArray BulkRound::ProcessMessage(int des_idx, int msg_index) { int count = _messages.size(); const Descriptor &des = GetDescriptors()[des_idx]; int length = des.Length(); QByteArray msg(length, 0); Hash hashalgo; bool good = true; for(int idx = 0; idx < count; idx++) { const char *tmsg = _messages[idx].constData() + msg_index; QByteArray xor_msg(QByteArray::fromRawData(tmsg, length)); if(des.XorMessageHashes()[idx] != hashalgo.ComputeHash(xor_msg)) { qWarning() << "Xor message does not hash properly"; _bad_message_hash.append(BadHash(des_idx, idx)); good = false; } if(good) { Xor(msg, msg, xor_msg); } } if(good) { return msg; } else { return QByteArray(); } }
void RepeatingBulkRound::ProcessMessages() { uint size = GetGroup().Count(); QByteArray cleartext(_expected_bulk_size, 0); foreach(QByteArray ciphertext, _messages) { Xor(cleartext, cleartext, ciphertext); }
BITBOARD ValidateComputeRookAttacks(int square) { BITBOARD attacks, temp_attacks; BITBOARD temp1, temp8; attacks=rook_attacks[square]; temp_attacks=And(attacks,Compl(Occupied)); temp_attacks=Compl(Or(temp_attacks,Compl(rook_attacks[square]))); temp1=And(temp_attacks,plus1dir[square]); temp8=And(temp_attacks,plus8dir[square]); attacks=Xor(attacks,plus1dir[FirstOne(temp1)]); attacks=Xor(attacks,plus8dir[FirstOne(temp8)]); temp1=And(temp_attacks,minus1dir[square]); temp8=And(temp_attacks,minus8dir[square]); attacks=Xor(attacks,minus1dir[LastOne(temp1)]); attacks=Xor(attacks,minus8dir[LastOne(temp8)]); return(attacks); }
static void F_func(char* In, char* Ki) { static char MR[48]; Transform(MR, In, E_Table, 48); Xor(MR, Ki, 48); S_func(In, MR); Transform(In, In, P_Table, 32); }
BITBOARD ValidateComputeBishopAttacks(int square) { BITBOARD attacks, temp_attacks; BITBOARD temp7, temp9; attacks=bishop_attacks[square]; temp_attacks=And(attacks,Compl(Occupied)); temp_attacks=Compl(Or(temp_attacks,Compl(bishop_attacks[square]))); temp7=And(temp_attacks,plus7dir[square]); temp9=And(temp_attacks,plus9dir[square]); attacks=Xor(attacks,plus7dir[FirstOne(temp7)]); attacks=Xor(attacks,plus9dir[FirstOne(temp9)]); temp7=And(temp_attacks,minus7dir[square]); temp9=And(temp_attacks,minus9dir[square]); attacks=Xor(attacks,minus7dir[LastOne(temp7)]); attacks=Xor(attacks,minus9dir[LastOne(temp9)]); return(attacks); }
void ac::AlphaBlendImageSubFilterXorRev(cv::Mat &frame) { if(blend_set == false || subfilter == -1 || ac::draw_strings[subfilter] == "AlphaBlendImageSubFilterXorRev") return; cv::Mat reimage, copy1; cv::resize(blend_image, reimage, frame.size()); CallFilter(subfilter, reimage); AlphaBlend(frame, reimage, copy1, 0.5); Xor(frame, copy1); AddInvert(frame); }
arithmtype Or(void) { arithmtype Res = Xor(); while(1) { if ( ErrorDesc ) break; if (*Expr=='|') { Expr++; Res = Res | Xor(); } else { break; } } return Res; }
Expression *XorExp::optimize(int result) { Expression *e; e1 = e1->optimize(result); e2 = e2->optimize(result); if (e1->isConst() == 1 && e2->isConst() == 1) e = Xor(type, e1, e2); else e = this; return e; }
void fullAdder(SD(sd), // Inputs: const Signal& A, const Signal& B, const Signal& Cin, // Outputs: const Signal& Sum, const Signal& Cout) { // This is a Module constructor. // The first argument is the display name for the module. // The second argument lists all of the input Signals. // The third argument lists all of the output Signals. // If fullAdder() is called directly by simnet(), this will put a "black box" // named "Full Adder" with three input leads and two output leads in the // simulation window. Module((sd, "Full Adder"), (A, B, Cin), (Sum, Cout) ); // Intermediate signals Signal AxorB; Signal AandB; Signal CandAxorB; // Because these components are inside a Module, they will not be visible in // the simulation. Xor(SD(sd, "1b"), (A, B), AxorB); And(SD(sd, "1b"), (A, B), AandB); And(SD(sd, "1b"), (AxorB, Cin), CandAxorB); Or (SD(sd, "1b"), (AandB, CandAxorB), Cout); Xor(SD(sd, "1b"), (Cin, AxorB), Sum); }
DWORD WINAPI Encrypt(PBYTE pbBuffer, TMyPAZEntry *pEntry) { CHAR szName[MAX_PATH]; BYTE bySeed[400]; DWORD dwSeed, dwSize; LPCSTR lpCrud; LPSTR lpExt, lpFileName; lpFileName = pEntry->szName; lstrcpy(szName, lpFileName); lpExt = findext(szName); if (lpExt && bIsVoice) { *lpExt = 0; } dwSize = pEntry->dwCompSize; lpCrud = GetCrud(findext(lpFileName), &GameInfo[dwInfoIndex]); if (lpCrud) dwSeed = sprintf((char *)bySeed, "%s %08X %s", strlwr(lpFileName), pEntry->dwCompSize, lpCrud ? lpCrud : ""); if (g_bIsMovie == False) { CBlowFish bf; bf.Initialize(GameInfo[dwInfoIndex].key[dwKeyIndex].DataKey, sizeof(GameInfo[dwInfoIndex].key[dwKeyIndex].DataKey)); if (lpCrud) { Decrypt(bySeed, dwSeed, pbBuffer, dwSize); } dwSize = bf.Encode(pbBuffer, pbBuffer, pEntry->dwDecryptSize); } else { if (dwInfoIndex != EF_FIRST) { memset(&bySeed[dwSeed + 10], 0, 0x100); DecryptMovie(&bySeed[dwSeed + 10], bySeed, dwSeed, pbBuffer, pEntry->dwCompSize); } else { } } if (bNeedXor) Xor(pbBuffer, dwSize); return dwSize; }
BinaryMatrix *BinaryMatrix::Mul(BinaryMatrix *other) { if (_col != other->GetRowCount()) return null; int resultMatrixRowCount = _row; int resultMatrixColCount = other->GetColCount(); BinaryMatrix *matrix = new BinaryMatrix(resultMatrixRowCount, resultMatrixColCount); for (int i = 0; i < resultMatrixRowCount; i++) { for (int j = 0; j < resultMatrixColCount; j++) { bool temp = false; for (int r = 0; r < _col; r++) { bool tempConjunction = GetItem(i, r) && other->GetItem(r, j); temp = Xor(temp, tempConjunction); } matrix->SetItem(i, j, temp); } } return matrix; };
int EncryptDate(char* indate,char* OutDate) { unsigned char MacBlock[32]={0},aryTmp[32]={0}; int iPos; unsigned long p_len = strlen(indate); iPos=0; while (iPos<p_len) { memset((char*)aryTmp,0,8); if(iPos+8>p_len) memcpy((char*)aryTmp,indate+iPos,p_len-iPos); else memcpy((char*)aryTmp,indate+iPos,8); iPos+=8; Xor((char*)MacBlock,(char*)aryTmp,8); // CStdDes::RunDes(1,1,(char *)aryTmp,(char *)MacBlock,8,(const char *)_TAK,8); } for(int i=0;i<8;i++) { sprintf(OutDate+i*2,"%02X",MacBlock[i]); } return 0; }
u32t _std dsk_gptactive(u32t disk, u32t index) { hdd_info *hi = get_by_disk(disk); u32t ii, changed; if (!hi) return DPTE_INVDISK; // function call rescan if required if (dsk_isgpt(disk,-1)<=0) return DPTE_MBRDISK; // check index if (index>=hi->gpt_view) return DPTE_PINDEX; if (!memchrd(hi->gpt_index, index, hi->gpt_size)) return DPTE_PINDEX; for (ii=0, changed=0; ii<hi->gpt_size; ii++) if (hi->ptg[ii].PTG_FirstSec) { struct GPT_Record *pte = hi->ptg + ii; int target = hi->gpt_index[ii]==index; // bit mismatch for this entry if (Xor(pte->PTG_Attrs & (1LL << GPTATTR_BIOSBOOT),target)) { changed++; if (target) pte->PTG_Attrs |= 1LL << GPTATTR_BIOSBOOT; else pte->PTG_Attrs &= ~(1LL << GPTATTR_BIOSBOOT); } } return changed ? update_rescan(hi) : 0; }
void SetChessBitBoards(SEARCH_POSITION *new_pos) { int i; search.hash_key=0; search.pawn_hash_key=0; /* place pawns */ search.w_pawn=0; search.b_pawn=0; for (i=0;i<64;i++) { if(search.board[i]==pawn) { search.w_pawn=Or(search.w_pawn,set_mask[i]); search.hash_key=Xor(search.hash_key,w_pawn_random[i]); search.pawn_hash_key=search.pawn_hash_key^w_pawn_random32[i]; } if(search.board[i]==-pawn) { search.b_pawn=Or(search.b_pawn,set_mask[i]); search.hash_key=Xor(search.hash_key,b_pawn_random[i]); search.pawn_hash_key=search.pawn_hash_key^b_pawn_random32[i]; } } /* place knights */ search.w_knight=0; search.b_knight=0; for (i=0;i<64;i++) { if(search.board[i] == knight) { search.w_knight=Or(search.w_knight,set_mask[i]); search.hash_key=Xor(search.hash_key,w_knight_random[i]); } if(search.board[i] == -knight) { search.b_knight=Or(search.b_knight,set_mask[i]); search.hash_key=Xor(search.hash_key,b_knight_random[i]); } } /* place bishops */ search.w_bishop=0; search.b_bishop=0; for (i=0;i<64;i++) { if(search.board[i] == bishop) { search.w_bishop=Or(search.w_bishop,set_mask[i]); search.hash_key=Xor(search.hash_key,w_bishop_random[i]); } if(search.board[i] == -bishop) { search.b_bishop=Or(search.b_bishop,set_mask[i]); search.hash_key=Xor(search.hash_key,b_bishop_random[i]); } } /* place rooks */ search.w_rook=0; search.b_rook=0; for (i=0;i<64;i++) { if(search.board[i] == rook) { search.w_rook=Or(search.w_rook,set_mask[i]); search.hash_key=Xor(search.hash_key,w_rook_random[i]); } if(search.board[i] == -rook) { search.b_rook=Or(search.b_rook,set_mask[i]); search.hash_key=Xor(search.hash_key,b_rook_random[i]); } } /* place queens */ search.w_queen=0; search.b_queen=0; for (i=0;i<64;i++) { if(search.board[i] == queen) { search.w_queen=Or(search.w_queen,set_mask[i]); search.hash_key=Xor(search.hash_key,w_queen_random[i]); } if(search.board[i] == -queen) { search.b_queen=Or(search.b_queen,set_mask[i]); search.hash_key=Xor(search.hash_key,b_queen_random[i]); } } /* place kings */ for (i=0;i<64;i++) { if(search.board[i] == king) { search.white_king=i; search.hash_key=Xor(search.hash_key,w_king_random[i]); } if(search.board[i] == -king) { search.black_king=i; search.hash_key=Xor(search.hash_key,b_king_random[i]); } } if (new_pos->enpassant_target) HashEP(new_pos->enpassant_target,search.hash_key); if (!(new_pos->w_castle&1)) HashCastleW(0,search.hash_key); if (!(new_pos->w_castle&2)) HashCastleW(1,search.hash_key); if (!(new_pos->b_castle&1)) HashCastleB(0,search.hash_key); if (!(new_pos->b_castle&2)) HashCastleB(1,search.hash_key); /* initialize combination boards that show multiple pieces. */ search.bishops_queens=Or(Or(Or(search.w_bishop,search.w_queen),search.b_bishop),search.b_queen); search.rooks_queens=Or(Or(Or(search.w_rook,search.w_queen),search.b_rook),search.b_queen); search.w_occupied=Or(Or(Or(Or(Or(search.w_pawn,search.w_knight),search.w_bishop),search.w_rook), search.w_queen),set_mask[search.white_king]); search.b_occupied=Or(Or(Or(Or(Or(search.b_pawn,search.b_knight),search.b_bishop),search.b_rook), search.b_queen),set_mask[search.black_king]); /* now initialize rotated occupied bitboards. */ search.occupied_rl90=0; search.occupied_rl45=0; search.occupied_rr45=0; for (i=0;i<64;i++) { if (search.board[i]) { search.occupied_rl90=Or(search.occupied_rl90,set_mask_rl90[i]); search.occupied_rl45=Or(search.occupied_rl45,set_mask_rl45[i]); search.occupied_rr45=Or(search.occupied_rr45,set_mask_rr45[i]); } } /* initialize black/white piece counts. */ search.white_pieces=0; search.white_pawns=0; search.black_pieces=0; search.black_pawns=0; search.material_evaluation=0; for (i=0;i<64;i++) { switch (search.board[i]) { case pawn: search.material_evaluation+=PAWN_VALUE; search.white_pawns+=pawn_v; break; case knight: search.material_evaluation+=KNIGHT_VALUE; search.white_pieces+=knight_v; break; case bishop: search.material_evaluation+=BISHOP_VALUE; search.white_pieces+=bishop_v; break; case rook: search.material_evaluation+=ROOK_VALUE; search.white_pieces+=rook_v; break; case queen: search.material_evaluation+=QUEEN_VALUE; search.white_pieces+=queen_v; break; case -pawn: search.material_evaluation-=PAWN_VALUE; search.black_pawns+=pawn_v; break; case -knight: search.material_evaluation-=KNIGHT_VALUE; search.black_pieces+=knight_v; break; case -bishop: search.material_evaluation-=BISHOP_VALUE; search.black_pieces+=bishop_v; break; case -rook: search.material_evaluation-=ROOK_VALUE; search.black_pieces+=rook_v; break; case -queen: search.material_evaluation-=QUEEN_VALUE; search.black_pieces+=queen_v; break; default: ; } } TotalPieces=PopCnt(Occupied); if (new_pos == &position[0]) { rephead_b=replist_b; rephead_w=replist_w; } }
bool wxRegion::Xor( const wxRect& rect ) { wxRegion reg( rect ); return Xor( reg ); }
void ValidatePosition(int ply, int move, char *caller) { BITBOARD temp, temp1, temp_occ, temp_occ_rl90, temp_occ_rl45; BITBOARD temp_occ_rr45, temp_occx, cattacks, rattacks; int i,square,error; int temp_score; /* first, test w_occupied and b_occupied */ error=0; temp_occ=Or(Or(Or(Or(Or(WhitePawns,WhiteKnights),WhiteBishops), WhiteRooks),WhiteQueens),WhiteKing); if(Xor(WhitePieces,temp_occ)) { Print(1,"ERROR white occupied squares is bad!\n"); Display2BitBoards(temp_occ,WhitePieces); error=1; } temp_occ=Or(Or(Or(Or(Or(BlackPawns,BlackKnights),BlackBishops), BlackRooks),BlackQueens),BlackKing); if(Xor(BlackPieces,temp_occ)) { Print(1,"ERROR black occupied squares is bad!\n"); Display2BitBoards(temp_occ,BlackPieces); error=1; } /* now test rotated occupied bitboards. */ temp_occ_rl90=0; temp_occ_rl45=0; temp_occ_rr45=0; for (i=0;i<64;i++) { if (PieceOnSquare(i)) { temp_occ_rl90=Or(temp_occ_rl90,set_mask_rl90[i]); temp_occ_rl45=Or(temp_occ_rl45,set_mask_rl45[i]); temp_occ_rr45=Or(temp_occ_rr45,set_mask_rr45[i]); } } if(Xor(OccupiedRL90,temp_occ_rl90)) { Print(1,"ERROR occupied squares (rotated left 90) is bad!\n"); Display2BitBoards(temp_occ_rl90,OccupiedRL90); error=1; } if(Xor(OccupiedRL45,temp_occ_rl45)) { Print(1,"ERROR occupied squares (rotated left 45) is bad!\n"); Display2BitBoards(temp_occ_rl45,OccupiedRL45); error=1; } if(Xor(OccupiedRR45,temp_occ_rr45)) { Print(1,"ERROR occupied squares (rotated right 45) is bad!\n"); Display2BitBoards(temp_occ_rr45,OccupiedRR45); error=1; } /* now test bishops_queens and rooks_queens */ temp_occ=Or(Or(Or(WhiteBishops,WhiteQueens),BlackBishops), BlackQueens); if(Xor(BishopsQueens,temp_occ)) { Print(1,"ERROR bishops_queens is bad!\n"); Display2BitBoards(temp_occ,BishopsQueens); error=1; } temp_occ=Or(Or(Or(WhiteRooks,WhiteQueens),BlackRooks), BlackQueens); if(Xor(RooksQueens,temp_occ)) { Print(1,"ERROR rooks_queens is bad!\n"); Display2BitBoards(temp_occ,RooksQueens); error=1; } /* check individual piece bit-boards to make sure two pieces don't occupy the same square (bit) */ temp_occ=Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor(Xor( WhitePawns,WhiteKnights),WhiteBishops),WhiteRooks), WhiteQueens),BlackPawns),BlackKnights),BlackBishops), BlackRooks),BlackQueens),WhiteKing),BlackKing); temp_occx=Or(Or(Or(Or(Or(Or(Or(Or(Or(Or(Or( WhitePawns,WhiteKnights),WhiteBishops),WhiteRooks), WhiteQueens),BlackPawns),BlackKnights),BlackBishops), BlackRooks),BlackQueens),WhiteKing),BlackKing); if(Xor(temp_occ,temp_occx)) { Print(1,"ERROR two pieces on same square\n"); error=1; } /* test material_evaluation */ temp_score=PopCnt(WhitePawns)*PAWN_VALUE; temp_score-=PopCnt(BlackPawns)*PAWN_VALUE; temp_score+=PopCnt(WhiteKnights)*KNIGHT_VALUE; temp_score-=PopCnt(BlackKnights)*KNIGHT_VALUE; temp_score+=PopCnt(WhiteBishops)*BISHOP_VALUE; temp_score-=PopCnt(BlackBishops)*BISHOP_VALUE; temp_score+=PopCnt(WhiteRooks)*ROOK_VALUE; temp_score-=PopCnt(BlackRooks)*ROOK_VALUE; temp_score+=PopCnt(WhiteQueens)*QUEEN_VALUE; temp_score-=PopCnt(BlackQueens)*QUEEN_VALUE; if(temp_score != Material) { Print(1,"ERROR material_evaluation is wrong, good=%d, bad=%d\n", temp_score,Material); error=1; } temp_score=PopCnt(WhiteKnights)*knight_v; temp_score+=PopCnt(WhiteBishops)*bishop_v; temp_score+=PopCnt(WhiteRooks)*rook_v; temp_score+=PopCnt(WhiteQueens)*queen_v; if(temp_score != TotalWhitePieces) { Print(1,"ERROR white_pieces is wrong, good=%d, bad=%d\n", temp_score,TotalWhitePieces); error=1; } temp_score=PopCnt(WhitePawns); if(temp_score != TotalWhitePawns) { Print(1,"ERROR white_pawns is wrong, good=%d, bad=%d\n", temp_score,TotalWhitePawns); error=1; } temp_score=PopCnt(BlackKnights)*knight_v; temp_score+=PopCnt(BlackBishops)*bishop_v; temp_score+=PopCnt(BlackRooks)*rook_v; temp_score+=PopCnt(BlackQueens)*queen_v; if(temp_score != TotalBlackPieces) { Print(1,"ERROR black_pieces is wrong, good=%d, bad=%d\n", temp_score,TotalBlackPieces); error=1; } temp_score=PopCnt(BlackPawns); if(temp_score != TotalBlackPawns) { Print(1,"ERROR black_pawns is wrong, good=%d, bad=%d\n", temp_score,TotalBlackPawns); error=1; } /* now test the board[...] to make sure piece values are correct. */ /* test pawn locations */ temp=WhitePawns; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != pawn) { Print(1,"ERROR! board[%d]=%d, should be 1\n",square, PieceOnSquare(square)); error=1; } Clear(square,temp); } temp=BlackPawns; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != -pawn) { Print(1,"ERROR! board[%d]=%d, should be -1\n",square, PieceOnSquare(square)); error=1; } Clear(square,temp); } /* test knight locations */ temp=WhiteKnights; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != knight) { Print(1,"ERROR! board[%d]=%d, should be 2\n",square, PieceOnSquare(square)); error=1; } Clear(square,temp); } temp=BlackKnights; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != -knight) { Print(1,"ERROR! board[%d]=%d, should be -2\n",square, PieceOnSquare(square)); error=1; } Clear(square,temp); } /* test bishop locations */ temp=WhiteBishops; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != bishop) { Print(1,"ERROR! board[%d]=%d, should be 3\n",square, PieceOnSquare(square)); error=1; } rattacks=AttacksBishop(square); cattacks=ValidateComputeBishopAttacks(square); if (rattacks != cattacks) { Print(1,"ERROR! bishop attacks wrong, square=%d\n",square); Display2BitBoards(rattacks,cattacks); error=1; } Clear(square,temp); } temp=BlackBishops; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != -bishop) { Print(1,"ERROR! board[%d]=%d, should be -3\n",square, PieceOnSquare(square)); error=1; } rattacks=AttacksBishop(square); cattacks=ValidateComputeBishopAttacks(square); if (rattacks != cattacks) { Print(1,"ERROR! bishop attacks wrong, square=%d\n",square); Display2BitBoards(rattacks,cattacks); error=1; } Clear(square,temp); } /* test rook locations */ temp=WhiteRooks; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != rook) { Print(1,"ERROR! board[%d]=%d, should be 4\n",square, PieceOnSquare(square)); error=1; } rattacks=AttacksRook(square); cattacks=ValidateComputeRookAttacks(square); if (rattacks != cattacks) { Print(1,"ERROR! Rook attacks wrong, square=%d\n",square); Display2BitBoards(rattacks,cattacks); error=1; } Clear(square,temp); } temp=BlackRooks; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != -rook) { Print(1,"ERROR! board[%d]=%d, should be -4\n",square, PieceOnSquare(square)); error=1; } rattacks=AttacksRook(square); cattacks=ValidateComputeRookAttacks(square); if (rattacks != cattacks) { Print(1,"ERROR! Rook attacks wrong, square=%d\n",square); Display2BitBoards(rattacks,cattacks); error=1; } Clear(square,temp); } /* test queen locations */ temp=WhiteQueens; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != queen) { Print(1,"ERROR! board[%d]=%d, should be 5\n",square, PieceOnSquare(square)); error=1; } rattacks=AttacksQueen(square); cattacks=Or(ValidateComputeRookAttacks(square),ValidateComputeBishopAttacks(square)); if (rattacks != cattacks) { Print(1,"ERROR! queen attacks wrong, square=%d\n",square); Display2BitBoards(rattacks,cattacks); error=1; } Clear(square,temp); } temp=BlackQueens; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != -queen) { Print(1,"ERROR! board[%d]=%d, should be -5\n",square, PieceOnSquare(square)); error=1; } rattacks=AttacksQueen(square); cattacks=Or(ValidateComputeRookAttacks(square),ValidateComputeBishopAttacks(square)); if (rattacks != cattacks) { Print(1,"ERROR! queen attacks wrong, square=%d\n",square); Display2BitBoards(rattacks,cattacks); error=1; } Clear(square,temp); } /* test king locations */ temp=WhiteKing; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != king) { Print(1,"ERROR! board[%d]=%d, should be 6\n",square, PieceOnSquare(square)); error=1; } if (WhiteKingSQ != square) { Print(1,"ERROR! white_king is %d, should be %d\n", WhiteKingSQ,square); error=1; } Clear(square,temp); } temp=BlackKing; while(temp) { square=FirstOne(temp); if (PieceOnSquare(square) != -king) { Print(1,"ERROR! board[%d]=%d, should be -6\n",square, PieceOnSquare(square)); error=1; } if (BlackKingSQ != square) { Print(1,"ERROR! black_king is %d, should be %d\n", BlackKingSQ,square); error=1; } Clear(square,temp); } /* test board[i] fully now. */ for (i=0;i<64;i++) switch (PieceOnSquare(i)) { case -king: if (!And(BlackKing,set_mask[i])) { Print(1,"ERROR! b_king/board[%d] don't agree!\n",i); error=1; } break; case -queen: if (!And(BlackQueens,set_mask[i])) { Print(1,"ERROR! b_queen/board[%d] don't agree!\n",i); error=1; } break; case -rook: if (!And(BlackRooks,set_mask[i])) { Print(1,"ERROR! b_rook/board[%d] don't agree!\n",i); error=1; } break; case -bishop: if (!And(BlackBishops,set_mask[i])) { Print(1,"ERROR! b_bishop/board[%d] don't agree!\n",i); error=1; } break; case -knight: if (!And(BlackKnights,set_mask[i])) { Print(1,"ERROR! b_knight/board[%d] don't agree!\n",i); error=1; } break; case -pawn: if (!And(BlackPawns,set_mask[i])) { Print(1,"ERROR! b_pawn/board[%d] don't agree!\n",i); error=1; } break; case king: if (!And(WhiteKing,set_mask[i])) { Print(1,"ERROR! w_king/board[%d] don't agree!\n",i); error=1; } break; case queen: if (!And(WhiteQueens,set_mask[i])) { Print(1,"ERROR! w_queen/board[%d] don't agree!\n",i); error=1; } break; case rook: if (!And(WhiteRooks,set_mask[i])) { Print(1,"ERROR! w_rook/board[%d] don't agree!\n",i); error=1; } break; case bishop: if (!And(WhiteBishops,set_mask[i])) { Print(1,"ERROR! w_bishop/board[%d] don't agree!\n",i); error=1; } break; case knight: if (!And(WhiteKnights,set_mask[i])) { Print(1,"ERROR! w_knight/board[%d] don't agree!\n",i); error=1; } break; case pawn: if (!And(WhitePawns,set_mask[i])) { Print(1,"ERROR! w_pawn/board[%d] don't agree!\n",i); error=1; } break; } /* test empty squares now */ temp=Compl(Or(temp_occ,temp_occx)); while(temp) { square=FirstOne(temp); if (PieceOnSquare(square)) { Print(1,"ERROR! board[%d]=%d, should be 0\n",square, PieceOnSquare(square)); error=1; } Clear(square,temp); } /* test total piece count now */ temp=PopCnt(Occupied); if (temp != TotalPieces) { Print(1,"ERROR! TotalPieces is wrong, correct=%d bad=%d\n", temp,TotalPieces); error=1; } /* test hash key */ temp=0; temp1=0; for (i=0;i<64;i++) { switch (PieceOnSquare(i)) { case king: temp=Xor(temp,w_king_random[i]); break; case queen: temp=Xor(temp,w_queen_random[i]); break; case rook: temp=Xor(temp,w_rook_random[i]); break; case bishop: temp=Xor(temp,w_bishop_random[i]); break; case knight: temp=Xor(temp,w_knight_random[i]); break; case pawn: temp=Xor(temp,w_pawn_random[i]); temp1=Xor(temp1,w_pawn_random[i]); break; case -pawn: temp=Xor(temp,b_pawn_random[i]); temp1=Xor(temp1,b_pawn_random[i]); break; case -knight: temp=Xor(temp,b_knight_random[i]); break; case -bishop: temp=Xor(temp,b_bishop_random[i]); break; case -rook: temp=Xor(temp,b_rook_random[i]); break; case -queen: temp=Xor(temp,b_queen_random[i]); break; case -king: temp=Xor(temp,b_king_random[i]); break; default: break; } } if (EnPassant(ply)) HashEP(EnPassant(ply),temp); if (!(WhiteCastle(ply)&1)) HashCastleW(0,temp); if (!(WhiteCastle(ply)&2)) HashCastleW(1,temp); if (!(BlackCastle(ply)&1)) HashCastleB(0,temp); if (!(BlackCastle(ply)&2)) HashCastleB(1,temp); if(Xor(temp,HashKey)) { Print(1,"ERROR! hash_key is bad.\n"); error=1; } if(Xor(temp1,PawnHashKey)) { Print(1,"ERROR! pawn_hash_key is bad.\n"); error=1; } if (error) { /* Print(0,"active path:\n"); for (i=1;i<=ply;i++) DisplayChessMove("move=",move); */ Print(0,"current move:\n"); DisplayChessMove("move=",move); DisplayChessBoard(stdout,search); Print(0,"called from %s, ply=%d\n",caller,ply); Print(0,"node=%d\n",nodes_searched+q_nodes_searched); exit(1); } }
void InitializeAttackBoards(void) { int i, j, frank, ffile, trank, tfile; int sq, lastsq; int knightsq[8]={-17,-15,-10,-6,6,10,15,17}; int bishopsq[4]={-9,-7,7,9}; int rooksq[4]={-8,-1,1,8}; BITBOARD sqs; /* initialize pawn attack boards */ for(i=0;i<64;i++) { w_pawn_attacks[i]=0; if (i < 56) for(j=2;j<4;j++) { sq=i+bishopsq[j]; if((abs(sq/8-i/8)==1) && (abs((sq&7) - (i&7))==1) && (sq < 64) && (sq > -1)) w_pawn_attacks[i]=Or(w_pawn_attacks[i],Shiftr(mask_1,sq)); } b_pawn_attacks[i]=0; if (i > 7) for(j=0;j<2;j++) { sq=i+bishopsq[j]; if((abs(sq/8-i/8)==1) && (abs((sq&7)-(i&7))==1) && (sq < 64) && (sq > -1)) b_pawn_attacks[i]=Or(b_pawn_attacks[i],Shiftr(mask_1,sq)); } } /* initialize knight attack board */ for(i=0;i<64;i++) { knight_attacks[i]=0; frank=i/8; ffile=i&7; for(j=0;j<8;j++) { sq=i+knightsq[j]; if((sq < 0) || (sq > 63)) continue; trank=sq/8; tfile=sq&7; if((abs(frank-trank) > 2) || (abs(ffile-tfile) > 2)) continue; knight_attacks[i]=Or(knight_attacks[i],Shiftr(mask_1,sq)); } } /* initialize bishop/queen attack boards and masks */ for(i=0;i<64;i++) { bishop_attacks[i]=0; for(j=0;j<4;j++) { sq=i; lastsq=sq; sq=sq+bishopsq[j]; while((abs(sq/8-lastsq/8)==1) && (abs((sq&7)-(lastsq&7))==1) && (sq < 64) && (sq > -1)) { bishop_attacks[i]=Or(bishop_attacks[i],Shiftr(mask_1,sq)); queen_attacks[i]=Or(queen_attacks[i],Shiftr(mask_1,sq)); if(bishopsq[j]==7) plus7dir[i]=Or(plus7dir[i],Shiftr(mask_1,sq)); else if(bishopsq[j]==9) plus9dir[i]=Or(plus9dir[i],Shiftr(mask_1,sq)); else if(bishopsq[j]==-7) minus7dir[i]=Or(minus7dir[i],Shiftr(mask_1,sq)); else minus9dir[i]=Or(minus9dir[i],Shiftr(mask_1,sq)); lastsq=sq; sq=sq+bishopsq[j]; } } } plus1dir[64]=0; plus7dir[64]=0; plus8dir[64]=0; plus9dir[64]=0; minus1dir[64]=0; minus7dir[64]=0; minus8dir[64]=0; minus9dir[64]=0; /* initialize rook/queen attack boards */ for(i=0;i<64;i++) { rook_attacks[i]=0; for(j=0;j<4;j++) { sq=i; lastsq=sq; sq=sq+rooksq[j]; while((((abs(sq/8-lastsq/8)==1) && (abs((sq&7)-(lastsq&7))==0)) || ((abs(sq/8-lastsq/8)==0) && (abs((sq&7)-(lastsq&7))==1))) && (sq < 64) && (sq > -1)) { rook_attacks[i]=Or(rook_attacks[i],Shiftr(mask_1,sq)); queen_attacks[i]=Or(queen_attacks[i],Shiftr(mask_1,sq)); if(rooksq[j]==1) plus1dir[i]=Or(plus1dir[i],Shiftr(mask_1,sq)); else if(rooksq[j]==8) plus8dir[i]=Or(plus8dir[i],Shiftr(mask_1,sq)); else if(rooksq[j]==-1) minus1dir[i]=Or(minus1dir[i],Shiftr(mask_1,sq)); else minus8dir[i]=Or(minus8dir[i],Shiftr(mask_1,sq)); lastsq=sq; sq=sq+rooksq[j]; } } } /* initialize king attack board */ for(i=0;i<64;i++) { king_attacks[i]=0; king_attacks_1[i]=0; king_attacks_2[i]=0; for (j=0;j<64;j++) { if (Distance(i,j) == 1) king_attacks[i]=Or(king_attacks[i],set_mask[j]); if (Distance(i,j) <= 1) king_attacks_1[i]=Or(king_attacks_1[i],set_mask[j]); if (Distance(i,j) <= 2) king_attacks_2[i]=Or(king_attacks_2[i],set_mask[j]); } } /* direction[sq1][sq2] gives the "move direction" to move from sq1 to sq2. obstructed[sq1][sq2] gives a bit vector that indicates which squares must be unoccupied in order for <sq1> to attack <sq2>, assuming a sliding piece is involved. to use this, you simply have to Or(obstructed[sq1][sq2],occupied_squares) and if the result is "0" then a sliding piece on sq1 would attack sq2 and vice-versa. */ for (i=0;i<64;i++) { for (j=0;j<64;j++) obstructed[i][j]=(BITBOARD) -1; sqs=plus1dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=1; obstructed[i][j]=Xor(plus1dir[i],plus1dir[j-1]); Clear(j,sqs); } sqs=plus7dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=7; obstructed[i][j]=Xor(plus7dir[i],plus7dir[j-7]); Clear(j,sqs); } sqs=plus8dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=8; obstructed[i][j]=Xor(plus8dir[i],plus8dir[j-8]); Clear(j,sqs); } sqs=plus9dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=9; obstructed[i][j]=Xor(plus9dir[i],plus9dir[j-9]); Clear(j,sqs); } sqs=minus1dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=-1; obstructed[i][j]=Xor(minus1dir[i],minus1dir[j+1]); Clear(j,sqs); } sqs=minus7dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=-7; obstructed[i][j]=Xor(minus7dir[i],minus7dir[j+7]); Clear(j,sqs); } sqs=minus8dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=-8; obstructed[i][j]=Xor(minus8dir[i],minus8dir[j+8]); Clear(j,sqs); } sqs=minus9dir[i]; while (sqs) { j=FirstOne(sqs); directions[i][j]=-9; obstructed[i][j]=Xor(minus9dir[i],minus9dir[j+9]); Clear(j,sqs); } } { int diag_sq[64] = { 0, 1, 0, 2, 1, 0, 3, 2, 1, 0, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 6, 5, 4, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4, 3, 2, 1, 0, 3, 2, 1, 0, 2, 1, 0, 1, 0, 0 }; int bias_rl45[64] = { 0, 1, 1, 3, 3, 3, 6, 6, 6, 6, 10, 10, 10, 10, 10, 15, 15, 15, 15, 15, 15, 21, 21, 21, 21, 21, 21, 21, 28, 28, 28, 28, 28, 28, 28, 28, 36, 36, 36, 36, 36, 36, 36, 43, 43, 43, 43, 43, 43, 49, 49, 49, 49, 49, 54, 54, 54, 54, 58, 58, 58, 61, 61, 63 }; int square, pcs, attacks; int rsq, tsq; int mask; /* initialize the rotated attack board that is based on the normal chess */ for (square=0;square<64;square++) { for (i=0;i<256;i++) { rook_attacks_r0[square][i]=0; rook_mobility_r0[square][i]=0; } for (pcs=0;pcs<256;pcs++) { attacks=InitializeFindAttacks(7-File(square),pcs,8); while (attacks) { sq=first_ones_8bit[attacks]; rook_attacks_r0[square][pcs]= Or(rook_attacks_r0[square][pcs],set_mask[(square&56)+sq]); attacks=attacks&(~(1<<(7-sq))); } rook_mobility_r0[square][pcs]=PopCnt(rook_attacks_r0[square][pcs]); } } /* initialize the rotated attack board that is based on one that rotated left 90 degrees (which lines up a file horizontally, rather than its normal vertical orientation.) */ for (square=0;square<64;square++) { for (i=0;i<256;i++) { rook_attacks_rl90[square][i]=0; rook_mobility_rl90[square][i]=0; } for (pcs=0;pcs<256;pcs++) { attacks=InitializeFindAttacks(Rank(square),pcs,8); while (attacks) { sq=first_ones_8bit[attacks]; rook_attacks_rl90[square][pcs]= Or(rook_attacks_rl90[square][pcs], set_mask[init_r90[((square&7)<<3)+sq]]); attacks=attacks&(~(1<<(7-sq))); } rook_mobility_rl90[square][pcs]=PopCnt(rook_attacks_rl90[square][pcs]); } } /* initialize the rotated attack board that is based on one that is rotated left 45 degrees (which lines up the (a8-h1) diagonal horizontally. */ for (square=0;square<64;square++) { for (i=0;i<256;i++) { bishop_attacks_rl45[square][i]=0; bishop_mobility_rl45[square][i]=0; } for (pcs=0;pcs<(1<<diagonal_length[init_l45[square]]);pcs++) { rsq=init_l45[square]; tsq=diag_sq[rsq]; attacks=InitializeFindAttacks(tsq,pcs,diagonal_length[rsq])<< (8-diagonal_length[rsq]); while (attacks) { sq=first_ones_8bit[attacks]; bishop_attacks_rl45[square][pcs]= Or(bishop_attacks_rl45[square][pcs], set_mask[init_ul45[sq+bias_rl45[rsq]]]); attacks=attacks&(~(1<<(7-sq))); } } mask=(1<<diagonal_length[init_l45[square]])-1; for (pcs=0;pcs<256;pcs++) { if ((pcs&mask) != pcs) bishop_attacks_rl45[square][pcs]= bishop_attacks_rl45[square][pcs&mask]; bishop_mobility_rl45[square][pcs]= PopCnt(bishop_attacks_rl45[square][pcs]); } } /* initialize the rotated attack board that is based on one that is rotated right 45 degrees (which lines up the (a1-h8) diagonal horizontally, */ for (square=0;square<64;square++) { for (i=0;i<256;i++) { bishop_attacks_rr45[square][i]=0; bishop_mobility_rr45[square][i]=0; } for (pcs=0;pcs<(1<<diagonal_length[init_r45[square]]);pcs++) { rsq=init_r45[square]; tsq=diag_sq[rsq]; attacks=InitializeFindAttacks(tsq,pcs,diagonal_length[rsq])<< (8-diagonal_length[rsq]); while (attacks) { sq=first_ones_8bit[attacks]; bishop_attacks_rr45[square][pcs]= Or(bishop_attacks_rr45[square][pcs], set_mask[init_ur45[sq+bias_rl45[rsq]]]); attacks=attacks&(~(1<<(7-sq))); } } mask=(1<<diagonal_length[init_r45[square]])-1; for (pcs=0;pcs<256;pcs++) { if ((pcs&mask) != pcs) bishop_attacks_rr45[square][pcs]= bishop_attacks_rr45[square][pcs&mask]; bishop_mobility_rr45[square][pcs]= PopCnt(bishop_attacks_rr45[square][pcs]); } } } }
/* ******************************************************************************** * * * LookUp() is used to retrieve entries from the transposition table so that * * this sub-tree won't have to be searched again if we reach a position that * * has been searched previously. a transposition table position contains the * * following data packed into 128 bits with each item taking the number of * * bits given in the table below: * * * * bits name SL description * * 3 age 61 search id to identify old trans/ref entried. * * 2 type 59 0->value is worthless; 1-> value represents a fail- * * low bound; 2-> value represents a fail-high bound; * * 3-> value is an exact score. * * 16 value 21 unsigned integer value of this position + 65536. * * this might be a good score or search bound. * * 21 move 0 best move from the current position, according to the * * search at the time this position was stored. * * * * 16 draft 48 the depth of the search below this position, which is * * used to see if we can use this entry at the current * * position. note that this is in units of 1/8th of a * * ply. * * 48 key 0 leftmost 48 bits of the 64 bit hash key. this is * * used to "verify" that this entry goes with the * * current board position. * * * ******************************************************************************** */ int LookUp(int ply, int depth, int wtm, int *alpha, int *beta) { register BITBOARD temp_hash_key; register HASH_ENTRY *htable; register int type, draft, avoid_null=WORTHLESS, val; /* ---------------------------------------------------------- | | | first, compute the initial hash address and choose | | which hash table (based on color) to probe. | | | ---------------------------------------------------------- */ hash_move[ply]=0; temp_hash_key=HashKey>>16; #if !defined(FAST) transposition_probes++; #endif /* ---------------------------------------------------------- | | | now, check both "parts" of the hash table to see if | | this position is in either one. | | | ---------------------------------------------------------- */ htable=((wtm)?trans_ref_wa:trans_ref_ba)+(((int) HashKey) & hash_maska); if (!Xor(And(htable->word2,mask_80),temp_hash_key)) do { #if !defined(FAST) transposition_hits++; #endif hash_move[ply]=((int) htable->word1) & 07777777; type=((int) Shiftr(htable->word1,59)) & 03; draft=(int) Shiftr(htable->word2,48); val=(((int) Shiftr(htable->word1,21)) & 01777777)-65536; if ((type & UPPER_BOUND) && depth-NULL_MOVE_DEPTH-INCREMENT_PLY <= draft && val < *beta) avoid_null=AVOID_NULL_MOVE; if (depth > draft) break; switch (type) { case EXACT_SCORE: if (abs(val) > MATE-100) { if (val > 0) val-=(ply-1); else val+=(ply-1); } *alpha=val; return(EXACT_SCORE); case UPPER_BOUND: if (val <= *alpha) { *alpha=val; return(UPPER_BOUND); } break; case LOWER_BOUND: if (val >= *beta) { *beta=val; return(LOWER_BOUND); } break; } } while(0); htable=((wtm)?trans_ref_wb:trans_ref_bb)+(((int) HashKey) & hash_maskb); if (!Xor(And(htable->word2,mask_80),temp_hash_key)) { #if !defined(FAST) transposition_hits++; #endif if (hash_move[ply]==0) hash_move[ply]=((int) htable->word1) & 07777777; type=((int) Shiftr(htable->word1,59)) & 03; draft=Shiftr(htable->word2,48); val=(((int) Shiftr(htable->word1,21)) & 01777777)-65536; if ((type & UPPER_BOUND) && depth-NULL_MOVE_DEPTH-INCREMENT_PLY <= draft && val < *beta) avoid_null=AVOID_NULL_MOVE; if (depth > draft) return(avoid_null); switch (type) { case EXACT_SCORE: if (abs(val) > MATE-100) { if (val > 0) val-=(ply-1); else val+=(ply-1); } *alpha=val; return(EXACT_SCORE); case UPPER_BOUND: if (val <= *alpha) { *alpha=val; return(UPPER_BOUND); } return(avoid_null); case LOWER_BOUND: if (val >= *beta) { *beta=val; return(LOWER_BOUND); } return(avoid_null); } } return(avoid_null); }