Zobrist Collisions?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
stevemulligan
Posts: 117
Joined: Wed Jul 20, 2011 2:54 pm
Location: Ottawa, Canada

Zobrist Collisions?

Post by stevemulligan »

I'm trying to implement transposition tables in my engine and I'm failing hard (pardon the pun, could not resist). I'm pretty sure a big part of the problem is an improper Zobrist implementation.

To debug my TT's I used a Dictionary instead of an array+modulus to rule out collisions that might be caused by the modulus. Each entry in the TT is unique.

Then I compare the current boards fen to the one stored in the TT. I assume they should always match. 35% of the entries have Fen strings that don't match.

eg: The following to Fen strings both map to the same Zobrist hash in my engine

[d]1q3rk1/p4pp1/2pb3p/3Q4/6Pr/1PN5/P1PB1PP1/4RRK1/ b - -

vs

[d]3q1rk1/p4pp1/2pb3p/3N4/8/1P1Q4/P1PB1Pr1/4RRK1/ w - -


I thought my Zobrist hashing was working because my opening book moves use them, but I'm guessing I was wrong and wanted to confirm with the experts here.

The hash before a Make matches the hash after an UnMake so that makes me wonder if the "random numbers" I chose to seed the hashes were not random enough? Is there a set of "approved" Zobrist values I can use to seed my hashes?


This code is what I use in Make/UnMake.

Code: Select all

int index = (((int)c * 7 + (int)p) * 64 + s);
currentZob = currentZob ^ Evaluation.zobKeys[index];
  • c, 0 is white, 1 is black.
    p 0=king -> 5=pawn. 6 is no piece.

And the random numbers I used for hashing (which probably doesn't help because there is too much to look at here but just in case I will post them):

Code: Select all

public static ulong[] zobKeys = new ulong[] { 17731183110302793728, 3828177388512477184, 18225327382047424512, 13020099548808347648, 17059564596900462592, 1930751428947345408, 3767823143122960384, 3654515556126949376, 15420227482169180160, 1431100644759961600, 1639968511349161984, 13952978907658059776, 17060270438602309632, 346472075516706816, 12356605999816048640, 8324738401947222016, 6364340829985767424, 14655466964945207296, 5593461036044976128, 5062775602977832960, 7811495341620264960, 10020624341328986112, 6533099832924897280, 4339542768367304704, 5897517801521348608, 17797232899478519808, 1189754944020480000, 16073380697893109760, 5376437323758895104, 4867286323835437056, 14674755028436058112, 18197594644117585920, 16559832256229736448, 3940948524729368576, 6315307993886031872, 13050429746713853952, 13569442485204484096, 1544655948610273280, 5223735169000079360, 11765042923781357568, 4761831836622585856, 10616769467958427648, 14508365135856992256, 15620668990447812608, 18174841589155561472, 1573606033629380608, 1668620936269463552, 3261311062766387200, 17687172247215734784, 9073853108868087808, 1489101555382812672, 5139451729030545408, 11792322394339999744, 12574650774449815552, 5933925889082851328, 8059122195601162240, 17741955764703526912, 7041846159256584192, 5282190026149134336, 10161732653085753344, 16710094786650767360, 14637294086343884800, 15393203268636049408, 3069189407514689536, 8361720852030488576, 8993994025228304384, 11213824756277248000, 12387917409350189056, 1239583711751897088, 719847688312193024, 10245036779276533760, 5079364232069644288, 18288397843648020480, 13187225268651032576, 5965096745175810048, 3271040630011854848, 9310570598373326848, 17658097153907884032, 9586324358695944192, 786185624508825600, 6411173514280239104, 8888027145428271104, 10830789509381292032, 801585536652410880, 9829654454430138368, 1793235522526380032, 2485849714082643968, 18091841201436491776, 11933152010279911424, 3215698735406252032, 8041556254811422720, 7645461626338541568, 1953879424563478528, 7410247926600171520, 9081788873483157504, 59462113309884416, 1089501499364540416, 12224788823331569664, 11182936474830176256, 17929460912290398208, 3442841207749017600, 12714180440653299712, 652319329218920448, 9502313214847090688, 6295671585517404160, 8800845695278907392, 13028871189520121856, 2292500692534427648, 3593729541263917056, 3605058562380005376, 9667711935602163712, 1072484625374117888, 18354886866793201664, 12211281306669547520, 16174688982533341184, 1879662584276320256, 9047156886427992064, 1359645502079762432, 714740615602438144, 3320015522753806336, 12187324306427543552, 632699539470417920, 5924040414309580800, 8731785461672574976, 5317496723267715072, 8752747337621962752, 13049458366318837760, 4981929914129055744, 11918024558327693312, 10235353015774609408, 18248738117364416512, 10297083193772343296, 13820732529618255872, 5966111117154189312, 17586801215492521984, 3797052613910200320, 2964101112835670016, 14560072632251711488, 4794108382544592896, 13039463041693515776, 4599462835833864192, 3711914645041446912, 5892511255498784768, 14527659601691541504, 16801869065828237312, 18132574860705529856, 12540381358963490816, 8142533126510477312, 18212893859047079936, 14594829999963635712, 6367563524895866880, 1934146944270467072, 3696710092796264448, 1897536951306682368, 12779140068176232448, 132432720902619136, 2952417327432138752, 3786538281895985152, 10126923335335870464, 3217701745701289984, 10641409180799401984, 5726499786473340928, 15081723186452299776, 17931715774151524352, 16755114915164127232, 2314266971532427264, 5481429936050208768, 7667038641062281216, 6723527093210644480, 13288133429550907392, 16983297518432092160, 2366144189157736448, 2125721942754131968, 1927859179169775616, 4265297326469218304, 14569308345266470912, 2474896621208403968, 17957595786437459968, 1252755781952143360, 1858028479675760640, 17086140431433269248, 10303169994492215296, 17849347255300456448, 13266030398309531648, 5059370879010013184, 1958995488521846784, 17320483428054532096, 13791144774501793792, 10162880919945150464, 17591840288776912896, 18160017433672220672, 4096520832158662656, 6392668885228781568, 7998297915115700224, 17329417311993659392, 11979746403027124224, 9353069814535749632, 8115452249024233472, 17833163814457507840, 1007042609313873920, 15469643047430062080, 12558284168628273152, 17652470933472608256, 13406870761322971136, 17903112733310386176, 13245965521507319808, 7260865385761538048, 577053444718592000, 4743250469018730496, 7274467125233188864, 3167392409662455808, 5565699991667867648, 5676066427482996736, 4382769952974438400, 15138136969418571776, 2103765357774110720, 4524547069749821440, 13740504235790827520, 8402845212268494848, 13321470547780567040, 3356825829723930624, 16979897931862900736, 2489555970859925504, 5598113756659712000, 10208102604070780928, 3546632760013094912, 12370238068744192000, 130583845087084544, 15721624859131052032, 8845395183120678912, 789810255997894656, 15587995096844730368, 4494668325485871104, 2338018116939808768, 11335256639145705472, 15444645271242932224, 7549842751687032832, 1076207194848100352, 3441744908839223296, 14223157484280741888, 8626684361324953600, 9620725972712554496, 8269090135376855040, 11370867842193948672, 13508455619111485440, 6615991184284975104, 10741535112954314752, 6265299485472456704, 9584608211497451520, 15444080554947903488, 3541754236100083712, 4759851507135414272, 16448253805347012608, 11793010197393571840, 9575951606674817024, 9277682576448684032, 11787031756694159360, 16659702194323849216, 5072881940166803456, 15033962588464611328, 10521964936749711360, 17958863302863618048, 12325019963052457984, 2570655058971983872, 3929558448977018880, 4939052145065328640, 3467256015660711936, 1153432222766333952, 15376765956340383744, 17204386457784156160, 16811459075874160640, 7724782494655840256, 11286889742048755712, 10294482705236623360, 18440863398774374400, 12344280594753126400, 4336855960487526400, 7884295446712811520, 5897506188675186688, 6165739176167079936, 16222785886989385728, 13218481849800589312, 16112088475789623296, 11922487449030885376, 15106032369755029504, 14467272380043755520, 14483124120374411264, 2405191650657566720, 16563743532035145728, 10983402500569694208, 13763913802074750976, 6520359512460886016, 834177368073764864, 4765078350460616704, 781093608550236160, 1580309988846731264, 8219963751102218240, 5135534258753896448, 334815366195380224, 8396143256963514368, 970086618610073600, 1711276609469939712, 3765972848022061056, 15963123461815926784, 14315644335049211904, 12447317288760639488, 8159339388008071168, 16123549021248815104, 17562926236861530112, 17030770847942180864, 8816769997029703680, 8323656797231906816, 17720525736493252608, 7054008538006290432, 7342517790533419008, 17823075497117614080, 794364561903648768, 14655355132644163584, 7953910356046184448, 8775541586253447168, 4741059828175142912, 10213857734491111424, 7180186889211805696, 15782776025679790080, 17301486189396951040, 5689708025426477056, 553200394983374848, 11823324731318599680, 3560469456740745216, 9481517240974049280, 16878075221268692992, 2014717082859077632, 10857881068967362560, 8391857088351174656, 12695071311945203712, 14503489424473325568, 16383248702393876480, 3321355822390837248, 15254112480242368512, 13046238088668512256, 2187028953555075072, 9019759484344205312, 13509690938018430976, 1541629264290775040, 6907598421632811008, 16701282856542928896, 16796607076428873728, 10502002860307906560, 3340160701741989888, 15026180854102884352, 258953054149083136, 14498817528180899840, 5976344622792769536, 4418606826067066880, 12990394166138830848, 13553959205304664064, 5330603504748003328, 3871692896786448384, 16268617587459817472, 17190768755852312576, 11830024797218734080, 4243397482599415808, 9337949061554831360, 12217291777225916416, 3507534526792138752, 16347786011073576960, 6714485897022078976, 7695282334655709184, 15470622809674285056, 5874596016885858304, 2019546483314065408, 271709513233596416, 16595228155510587392, 14977887740948643840, 3761267632301867008, 16345308873206661120, 17971829716035371008, 10816678874242351104, 948605972773535744, 13363156872696823808, 8144172362790404096, 8337660936415608832, 6382672827231698944, 17801656788778352640, 3795416631992188928, 1697957855035392000, 1280753517671415808, 1798244333077528576, 12953195492163256320, 10593394215515586560, 10512732679258439680, 8551797261965066240, 12677980606939332608, 5638131775680020480, 224820527926804480, 3830263352718393344, 960251704077254656, 1059268841970073600, 4388183081933012992, 5587108317758357504, 11461690561511096320, 3656924760442929152, 12411230779239235584, 15774854697745252352, 10196069044745207808, 12851733888469041152, 9924338972109504512, 1756493245923590144, 14137636948851359744, 6812192780175015936, 16266595663697608704, 17008003983635775488, 11726701326267908096, 15686330349876674560, 3322951242972332032, 9148923042518138880, 10999132621134430208, 13048952653253967872, 13396800638462132224, 759765316934959104, 2042304373709930496, 7279297263587557376, 4325180226741403648, 12460158154039492608, 11238524470665216000, 8686419295348981760, 17450705607683932160, 2147436695066902528, 4476946934918873088, 15905278198047571968, 12708609489899552768, 9560857811185696768, 18319424344103649280, 6414616840557297664, 7361163900296036352, 6967649351885783040, 7787250675783892992, 15287130562136637440, 6393449754290225152, 8238912343464345600, 17818369385901391872, 144988084259258368, 18156601863602634752, 6257750471908917248, 11917070742818979840, 10689810866250186752, 16301849641072132096, 1589523565182320640, 11691364151464099840, 16548801918176591872, 10409083521005191168, 4377381329993596928, 11530117260787384320, 15541059308421382144, 4541580211125682176, 6369988406400122880, 2442468426374512640, 9924917470605344768, 4422204423494369280, 4984294989740244992, 15460279194419527680, 16654335720684781568, 1365938367656558592, 15908126618436894720, 2835201243130953728, 7392269826875981824, 14624335080662958080, 4340503675068874752, 4899288964963565568, 13465336758716334080, 9470885332840284160, 3510573855685345280, 12850478668857278464, 8971148872593178624, 4414064897933639680, 17799980626028920832, 15697206833532698624, 15526636062399266816, 11069342394084163584, 9869277112071749632, 512668683900878848, 2314883242846060544, 3828452790204825600, 5523412072287830016, 17767667258017251328, 9344369020228075520, 7011922922192699392, 6285432961151401984, 7170457923930882048, 2520399338570514432, 5465519841260273664, 3755408927992971264, 4855507380472709120, 9998294335891963904, 1316665779849986048, 9678861768071184384, 17429260005792612352, 7576243815286571008, 12084265461761638400, 604225706278387712, 7614655745782775808, 7480380273074110464, 15913365853572628480, 12975569731896868864, 15414516897212334080, 3579340196139761664, 14343948925981622272, 16322215542992273408, 135726872270798848, 9121928667037171712, 7351806270643306496, 5980948545812692992, 17622562634593271808, 15230953730711486464, 16625718078623383552, 8055833323566661632, 17758672926444683264, 10562382715883880448, 11131996105952657408, 4026064868860100608, 5003533339327004672, 8349456640201719808, 8617616427635638272, 12117893286895157248, 6274234558669717504, 396914802410389504, 4833535228943204352, 13365836435536347136, 1270052646267453440, 5422513627838545920, 14909482830897807360, 5724571720489238528, 4724837022637031424, 3353734095183806464, 12743700992296943616, 3702905530497761280, 9271685136833380352, 6528908735263277056, 11219606416280715264, 4184134203959017472, 1656602149545377792, 7190439687936540672, 16840268316341633024, 7948774840292212736, 4186327681993867264, 1748764421319557120, 12906250995230769152, 16460560750294990848, 12449494816133545984, 8204227991993843712, 18017738265699221504, 3139151667161071616, 12602089039580430336, 8693168104640872448, 8409214005338112000, 723818477942079488, 10023019880411627520, 2711025616440000512, 8301556064258555904, 15180885227619614720, 15252369753536266240, 16632537726480547840, 6849420455864107008, 10371594602881875968, 10575890975761432576, 4356442878137597952, 12210545012236550144, 791070540927729664, 12793721423882944512, 3780914302780702720, 7791907311936274432, 4916947389520674816, 10824374628029104128, 9765672103389167616, 17855969099909103616, 15922949318224248832, 4098556426178330624, 4944026701311508480, 8377091535315075072, 12307194003714080768, 9979045547267653632, 5689851963353333760, 3099146079599788032, 15108187444464713728, 3341952782074183680, 4131033843568214016, 2715082663756759040, 5559366133032288256, 17748367611562622976, 720429793883193344, 4069302906203865088, 7507200750890385408, 16167151926655385600, 4073307361501511680, 1594273158002835456, 14581114827381538816, 3358437017139871744, 5862071514014941184, 10439159735279616000, 2619862945762770944, 10308339195323154432, 8086857549154877440, 1350147153709432832, 3560272766249336832, 13910692653324632064, 9905901891866591232, 12810101508973461504, 7721620970006249472, 1743790562590392320, 16073827936617627648, 1895048494218149888, 528569440654196736, 2771793255484162048, 2480401332857208832, 1484316487642972160, 6634318551911366656, 9472350811968831488, 9943363081610461184, 6681987556548739072, 13265731143058718720, 8667048276565753856, 8323883156635910144, 4365844417376878592, 15623854985022668800, 9389842691265724416, 3766109097173712896, 3614509702359220224, 1724477560410210304, 7873120892459745280, 2953847854464761856, 8123765979886321664, 17807491312870883328, 15238005214789828608, 7157314801040883712, 4259267303356170240, 633835771059109888, 5998097019752480768, 17460236215607623680, 11660400468868136960, 3043780890721124352, 13760178039482810368, 8367702426571505664, 14020327027394150400, 5620284987987329024, 1484206733132103680, 11521226698259169280, 1722346231735713792, 10128219811232481280, 10190761072930652160, 14692231333367775232, 723935154531926016, 1600023660158648320, 11072564691971407872, 2836843201556643840, 14272953088854654976, 15245453055594725376, 17461588649195929600, 13445514982423265280, 6830622057746857984, 14583920516382457856, 18400278612904574976, 1562627539146113024, 10251135133958995968, 11735395569968218112, 16001011998757814272, 8748036880845504512, 13176062640689709056, 4499927593139175424, 3291173501721706496, 14884360426439835648, 5928187842471591936, 2662223061334228992, 1307663466879844352, 14701777127122403328, 1991382435421683712, 8536825113865224192, 5900805787343978496, 11040418690378760192, 7676598286286258176, 807423633763205120, 2239652115931267072, 3438099432462090240, 6275533727823757312, 15132334584510414848, 11639973820589998080, 16311521694611406848, 18316200299651334144, 6354708475154399232, 2913867413981298688, 3400109803864326144, 3442995416160993280, 10715531275028004864, 10704844211863486464, 5465564821462974464, 14078792899529998336, 11671832456654618624, 16812401590657417216, 7419443207059013632, 18401469139768770560, 8233480437732343808, 8518211666409488384, 1903298520366186496, 16286220842771087360, 14734136321745223680, 17892453435526152192, 124947148066783232, 10832509611305795584, 17975098679693017088, 14236909220322934784, 5946944642996764672, 1030546110484512768, 10791075930199949312, 3994062711039787008, 17921978302042472448, 3378934914728263680, 8701175466888396800, 6900341662476468224, 6720987479148855296, 8345052759908614144, 12743638931180748800, 12814332401086955520, 3478095236923129856, 12145271008394412032, 4385256087553703936, 15506385215993217024, 6815605502157520896, 13037951319831674880, 10782716016592289792, 16587416056410734592, 11320091728180936704, 7252071139937812480, 15563364329742532608, 12433718299442610176, 9117350561804713984, 1579787110491029504, 11432002909163618304, 11675318423971233792, 18075798977602125824, 16415217975638032384, 8567600604049965056, 6284476173862109184, 5137573020488695808, 16563752569939623936, 9800144931509370880, 2263394199062249472, 4682094471668563968, 12922377667288432640, 2806243001408028672, 3194018408796323840, 16292781525318238208, 6585110153545056256, 16486754657796751360, 854924298403512320, 17226725899972902912, 5817365236743864320, 6239242218341793792, 4383220835553705984, 7871918081326186496, 7337797051893612544, 12294478493454303232, 8957823033080872960, 9090288211127697408, 7567688495993126912, 14427813051768635392, 3751669333016510464, 15987602819497852928, 7439299967831703552, 9585616335758295040, 10910122205316710400, 13877610891223498752, 4652342074046349312, 11909730481055334400, 1858133243498659840, 16169678008598921216, 7379962237757620224, 4408312726872784896, 17051484283269087232, 13730750588713435136, 2265569209877200896, 6759557934029078528, 11219594042847068160, 17472861825069744128, 852135648671236096, 2590308091473821696, 288407907413852160, 12196622306558607360, 6175934193595514880, 9739558817263386624, 3162364532482179072, 9367658870875095040, 12047763847812415488, 1671394782983094272, 12624488367488827392, 15236415436943785984, 14557718980943609856, 18047815695676866560, 15179616387016228864, 3785311535460777984, 10305443673886621696, 7857429536792510464, 759675989518254080, 4157821456490168320, 900354694436814848, 709758715843182592, 850574588352200704, 11183064084081541120, 7372769102071791616, 14578784155039301632, 16797173192422129664, 698245939049005056, 10856900595582435328, 13966255603024789504, 7508418277670715392, 9145572380878569472, 4065436123430584320, 12360512405325611008, 11300663812051501056, 14081076826275840000, 4117518202262716416, 15141924285752410112, 17743549307740815360, 11631931251688734720, 16540929060420124672, 3604695067690139648, 12142359365685936128, 285169529866158080, 13123792789026045952, 16721149201180393472, 11862835149188956160, 5154579774147133440, 1045818856170258432, 11035534210613772288, 17221123401964388352, 14226039664392273920, 3453022319753232384, 18006669983030050816, 17034891884307480576, 2421391116029657088, 9856421358174928896, 10497361380780670976, 6913383505018290176, 16430480109669974016, 7003778907082784768, 4771423853433454592, 1175265383079018496, 3398126850856452096, 7476291185896521728, 11799916148040794112, 17870476533715501056, 319075438096285696, 10125643596283707392, 8005091804947021824, 2941636629307392000, 795822964947550208, 15202370652463366144, 11675908786536972288, 2828671427232202752, 10088980635949465600, 12648390807281926144, 15581120581666996224, 396769105413996544, 11937746799010512896, 3791810902048571392, 3093690797676953600, 6215626492448145408, 3994897608686960640, 14817215690204971008, 7276933833743794176, 11923021346591014912, 15215643151233187840, 14306993091137437696, 3392596930398126080, 5700180492251889664, 53616660600324096, 1528282202736623616, 2989848509766303744, 12254331128141119488, 4286699255653203968, 2855499688266629120, 8530419719629307904, 14212982693329698816, 8213776934604636160, 4157580815809839104, 12135729505010581504, 12697989553630543872, 3092869769287434240, 7945392303890694144, 2831996787257376768, 1443797511458848768, 3890644071658553344, 11239078324002816000, 1522694210743566336, 17143003256443437056, 8741279045250187264, 2325565199507980288, 7368989651422281728 };
wgarvin
Posts: 838
Joined: Thu Jul 05, 2007 5:03 pm
Location: British Columbia, Canada

Re: Zobrist Collisions?

Post by wgarvin »

What are the numbers for "no piece" used for? They should all be zero (or you should just not include them in the table at all).

If you are (for example) reading the "piece" from the target square, and for non-captures it is always 6, but you are XORing a non-zero value from the table for that square (when it "captures" the empty square) then that is probably wrong.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Zobrist Collisions?

Post by sje »

Why are all of your "random" numbers even?
smatovic
Posts: 2663
Joined: Wed Mar 10, 2010 10:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic

Re: Zobrist Collisions?

Post by smatovic »

you can take a look at the Polyglot sample implementation of zobrist hashing:

http://alpha.uhasselt.be/Research/Algeb ... ormat.html

afaik the code is public domain.

--
Srdja
User avatar
stevemulligan
Posts: 117
Joined: Wed Jul 20, 2011 2:54 pm
Location: Ottawa, Canada

Re: Zobrist Collisions?

Post by stevemulligan »

I've taken "no piece" out of the code. Not sure why I had that in there to begin with. And the random numbers have been regenerated and look much better now. Must have been a Perl bug.

Still getting about 27% of my lookups that do not have matching fen strings. That's a bit better. I will take a look at how Polyglot does it.


old random # generation in Perl (always creates even numbers, very odd! :))

Code: Select all

for &#40;my $i = 0; $i < 2; $i++)
&#123;
 for &#40;my $j = 0; $j < 7; $j++)
 &#123;
   for &#40;my $k = 0; $k < 64; $k++)
   &#123;
   my $x = int&#40;rand&#40;18446744073709551615 ));
   print $x . "\n";
   &#125;
 &#125;
&#125;

Updated to python, these look better:

Code: Select all

import random

for i in range&#40;2&#41;&#58;
 for j in range&#40;6&#41;&#58;
  for k in range&#40;64&#41;&#58;
   print random.randint&#40;0, 18446744073709551615&#41;
micron
Posts: 155
Joined: Mon Feb 15, 2010 9:33 am
Location: New Zealand

Re: Zobrist Collisions?

Post by micron »

stevemulligan wrote:Still getting about 27% of my lookups that do not have matching fen strings.
In addition to the color/piece/square table you need 4 Zobrist values for castling rights, and 8 for e.p. file (or, wastefully, 64 for e.p. square). Also, in MakeMove() you should have something like:

Code: Select all

theBoard->hashCode = ~theBoard->hashCode; // change sides
Robert P.
SvenR

Re: Zobrist Collisions?

Post by SvenR »

stevemulligan wrote: This code is what I use in Make/UnMake.

Code: Select all

int index = ((&#40;int&#41;c * 7 + &#40;int&#41;p&#41; * 64 + s&#41;;
currentZob = currentZob ^ Evaluation.zobKeys&#91;index&#93;;
  • c, 0 is white, 1 is black.
    p 0=king -> 5=pawn. 6 is no piece.
Just making sure: You do that for both the source and destination squares, right?
User avatar
stevemulligan
Posts: 117
Joined: Wed Jul 20, 2011 2:54 pm
Location: Ottawa, Canada

Re: Zobrist Collisions?

Post by stevemulligan »

SvenR wrote: Just making sure: You do that for both the source and destination squares, right?
Correct. I have a ClearSquare and a PlacePiece function which both update the hash.

The implementation on chessbin.com doesn't mention that I need indexes for who's turn, castling & ep file.

If I break at the first occurance of a hash/fen mismatch, it's because the side to move is wrong. I'm pretty sure after I account for the parts that I'm missing it will start working. Many thanks for the help.
Miguel Angel

Re: Zobrist Collisions?

Post by Miguel Angel »

For testing purposes you can try changing temporaly (o definitly) your random numbers for the Polyglot random numbers:

Code: Select all

( http&#58;//alpha.uhasselt.be/Research/Algebra/Toga/book_format.html )
starting position
FEN=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
key=463b96181691fc9c

position after e2e4
FEN=rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1
key=823c9b50fd114196

position after e2e4 d75
FEN=rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2
key=0756b94461c50fb0

position after e2e4 d7d5 e4e5
FEN=rnbqkbnr/ppp1pppp/8/3pP3/8/8/PPPP1PPP/RNBQKBNR b KQkq - 0 2
key=662fafb965db29d4

position after e2e4 d7d5 e4e5 f7f5
FEN=rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPP1PPP/RNBQKBNR w KQkq f6 0 3
key=22a48b5a8e47ff78

position after e2e4 d7d5 e4e5 f7f5 e1e2
FEN=rnbqkbnr/ppp1p1pp/8/3pPp2/8/8/PPPPKPPP/RNBQ1BNR b kq - 0 3
key=652a607ca3f242c1

position after e2e4 d7d5 e4e5 f7f5 e1e2 e8f7
FEN=rnbq1bnr/ppp1pkpp/8/3pPp2/8/8/PPPPKPPP/RNBQ1BNR w - - 0 4
key=00fdd303c946bdd9

position after a2a4 b7b5 h2h4 b5b4 c2c4
FEN=rnbqkbnr/p1pppppp/8/8/PpP4P/8/1P1PPPP1/RNBQKBNR b KQkq c3 0 3
key=3c8123ea7b067637

position after a2a4 b7b5 h2h4 b5b4 c2c4 b4c3 a1a3
FEN=rnbqkbnr/p1pppppp/8/8/P6P/R1p5/1P1PPPP1/1NBQKBNR b Kkq - 0 4
key=5c3f9b829b279560
It was very useful for testing my own implementation of zobrist keys.
Another useful test is be sure that
incremental-generation-method == from-scratch-method
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Zobrist Collisions?

Post by Sven »

stevemulligan wrote:
SvenR wrote: Just making sure: You do that for both the source and destination squares, right?
Correct. I have a ClearSquare and a PlacePiece function which both update the hash.

The implementation on chessbin.com doesn't mention that I need indexes for who's turn, castling & ep file.

If I break at the first occurance of a hash/fen mismatch, it's because the side to move is wrong. I'm pretty sure after I account for the parts that I'm missing it will start working. Many thanks for the help.
And beware of the e.p. pitfalls :-)

1) After pawn double step to a square with an adjacent enemy pawn, you set the e.p. square in your position state. You might also check whether the e.p. capture would actually be legal for the enemy (pinned?) but this can become a bit expensive.
This will always affect the hashkey.

2) All other moves lead to a cleared e.p. square.
This can affect the hashkey.


3) If the previous position had an e.p. square set then XOR this (resp. the old e.p. file) to the hashkey

4) In addition to 3), if the new position has an e.p. square set then XOR this (resp. the new e.p. file) to the hashkey.

Think of the special case where both sides make a pawn double step and create an e.p. target square with their move => e.p. square is not *cleared* but *changed* with the second move. For this reason I do steps 3) and 4) independently.

Sven