Zobrist hashing

Zobrist hashing (also referred to as Zobrist keys or Zobrist signatures [1]) is a hash function construction used in computer programs that play abstract board games, such as chess and Go, to implement transposition tables, a special kind of hash table that is indexed by a board position and used to avoid analyzing the same position more than once. Zobrist hashing is named for its inventor, Albert Lindsey Zobrist.[2] It has also been applied as a method for recognizing substitutional alloy configurations in simulations of crystalline materials.[3] Zobrist hashing is the first known instance of the generally useful underlying technique called tabulation hashing.

Calculation of the hash value

Zobrist hashing starts by randomly generating bitstrings for each possible element of a board game, i.e. for each combination of a piece and a position (in the game of chess, that's 12 pieces × 64 board positions, or 18 × 64 if kings and rooks that may still castle,[dubiousdiscuss] and pawns that may capture en passant, are treated separately for both colors). Now any board configuration can be broken up into independent piece/position components, which are mapped to the random bitstrings generated earlier. The final Zobrist hash is computed by combining those bitstrings using bitwise XOR. Example pseudocode for the game of chess:[citation needed]

constant indices
    white_pawn := 1
    white_rook := 2
    # etc.
    black_king := 12

function init_zobrist():
    # fill a table of random numbers/bitstrings
    table := a 2-d array of size 64×12
    for i from 1 to 64:  # loop over the board, represented as a linear array
        for j from 1 to 12:      # loop over the pieces
            table[i][j] := random_bitstring()
    table.black_to_move = random_bitstring()

function hash(board):
    h := 0
    if is_black_turn(board):
        h := h XOR table.black_to_move
    for i from 1 to 64:      # loop over the board positions
        if board[i] ≠ empty:
            j := the piece at board[i], as listed in the constant indices, above
            h := h XOR table[i][j]
    return h

Use of the hash value

If the bitstrings are long enough, different board positions will almost certainly hash to different values; however longer bitstrings require proportionally more computer resources to manipulate. The most commonly used bitstring (key) length is 64 bits.[1] Many game engines store only the hash values in the transposition table, omitting the position information itself entirely to reduce memory usage, and assuming that hash collisions will not occur, or will not greatly influence the results of the table if they do.

Zobrist hashing is the first known instance of tabulation hashing. The result is a 3-wise independent hash family. In particular, it is strongly universal.

As an example, in chess, at any one time each of the 64 squares can at any time be empty, or contain one of the 6 game pieces, which are either black or white. Also, it can be either black's turn to play or white's turn to play. Thus one needs to generate 6 x 2 x 64 + 1 = 769 random bitstrings. Given a position, one obtains its Zobrist hash by finding out which pieces are on which squares, and combining the relevant bitstrings together. If the position is black to move, the black-to-move bitstring is also included in the Zobrist hash.[1]

Updating the hash value

Rather than computing the hash for the entire board every time, as the pseudocode above does, the hash value of a board can be incrementally updated simply by XORing out the bitstring(s) for positions that have changed, and XORing in the bitstrings for the new positions.[1] For instance, if a pawn on a chessboard square is replaced by a rook from another square, the resulting position would be produced by XORing the existing hash with the bitstrings for:

'pawn at this square'      (XORing out the pawn at this square)
'rook at this square'      (XORing in the rook at this square)
'rook at source square'    (XORing out the rook at the source square)

This makes Zobrist hashing very efficient for traversing a game tree.

In computer Go, this technique is also used for superko detection.

Wider usage

More generically, Zobrist hashing can be applied over finite sets of elements (in the chess example, these elements are tuples), as long as a random bitstring can be assigned to each possible element. This can be either done with a random number generator for smaller element spaces, or with a hash function for larger ones. This method has been used to recognize substitutional alloy configurations during Monte Carlo simulations in order to prevent wasting computational effort on states that have already been calculated.[3]

See also

References

  1. ^ a b c d Bruce Moreland. Zobrist keys: a means of enabling position comparison.
  2. ^ Albert Lindsey Zobrist, A New Hashing Method with Application for Game Playing, Tech. Rep. 88, Computer Sciences Department, University of Wisconsin, Madison, Wisconsin, (1969).
  3. ^ a b Mason, D. R.; Hudson, T. S.; Sutton, A. P. (2005). "Fast recall of state-history in kinetic Monte Carlo simulations utilizing the Zobrist key". Computer Physics Communications. 165 (1): 37–48. Bibcode:2005CoPhC.165...37M. doi:10.1016/j.cpc.2004.09.007.

Read other articles:

Toyota iQInformasiProdusenToyotaJuga disebutScion iQMasa produksi2008–2016PerakitanTakaoka, JepangPerancangToyota ED2Bodi & rangkaKelasMobil kotaBentuk kerangkahatchback 3 pintuTata letakMesin depan, penggerak roda depanMobil terkaitAston Martin CygnetPenyalur dayaMesin1.0 L I31.3 L bensin I41.4 L diesel I4Transmisi5-speed manual,6-speed manual,CVTDimensiJarak sumbu roda2.000 mm (78,7 in)PanjangToyota iQ: 2.985 mm (117,5 in)Scion iQ: 30.505 …

Breakup BuddiesPoster resmiNama lainTionghoa心花路放MandarinXīn Huā Lù FàngArtiHappiness on the Road SutradaraNing HaoProduserWang YibingLing HongDitulis olehYue XiaojunXing AinaSun XiaohangDong RunnianZhang DishaZhang YifanPemeranHuang BoXu ZhengYuan QuanPenata musikNathan WangDong DongdongSinematograferSong XiaofeiPenyuntingDu YuanPerusahaanproduksiInjo FilmsChina Film GroupBeijing Galloping Horse FilmBeijing Asian Union Culture & Media InvestmentTalent International Fi…

Liebherr GroupLiebherr di Gillette, WyomingJenisAktiengesellschaftIndustriAlat beratDidirikan1949; 75 tahun lalu (1949)KantorpusatBulle, SwissTokohkunciIsolde Liebherr dan Willi Liebherr, CEO & ChairmanProdukPeralatan konstruksi, mesin pertanian, kulkasPendapatan € 10,551 milyar.[1] (2018)Laba operasi € 632 juta [1] (2018)Laba bersih € 321 juta[1] (2018)Total aset € 13,785 milyar[1] (2018)Total ekuitas € 7,570 milyar[1 …

Bangunan tradisional di Inggris, abad ke-16 setengah-kayu dan bangunan setelahnya Rumah senapan adalah contoh vernakular sehari-hari di Amerika: Sepasang rumah senapan tunggal, yang berasal dari tahun 1920-an, di Campground Historic District, Mobile, Alabama Rumah batu dan tanah liat di pedesaan Nepal Rumah tradisional Batak Toba, Sumatera Utara, Indonesia Serangkaian unit motel menyerupai praktik bangunan tradisional pedesaan di dekat Taman Nasional Gunung Rainier di negara bagian Washington. K…

Group of indigenous peoples of South America and of the Caribbean For other uses, see Arawak (disambiguation). ArawakArawak woman, by John Gabriel StedmanRegions with significant populationsSouth America, CaribbeanLanguagesArawak, Arawakan languages, Taino, Caribbean English, Caribbean Spanish, Creole languagesReligionNative American religion, Christianity The Arawak are a group of indigenous peoples of northern South America and of the Caribbean. Specifically, the term Arawak has been applied a…

Ini adalah nama Korea; marganya adalah Ko. Go Ah-sungPekerjaanAktrisTahun aktif2004–sekarangNama KoreaHangul고아성 Alih AksaraGo AseongMcCune–ReischauerKo A-sŏng Go Ah-sung (Hangul: 고아성; lahir 10 Agustus 1992) adalah aktris asal Korea Selatan. Filmografi Film Tahun Judul Peran Catatan Ref. 2006 The Host Park Hyun-seo 2007 The Happy Life Joo-hee 2008 Radio Dayz Soon-deok 2009 A Brand New Life Ye-shin After the Banquet Kim Mi-rae [1] 2010 Sixteen film pendek …

Marginal sea of the northeastern Indian Ocean Andaman SeaBurma SeaLocation of Andaman Sea in the Indian OceanAndaman SeaCoordinates10°N 96°E / 10°N 96°E / 10; 96TypeSeaBasin countriesIndiaIndonesiaMalaysiaMyanmarThailandMax. length1,202 km (747 mi)Max. width647 km (402 mi)Surface area797,000 km2 (307,700 sq mi)Average depth1,096 m (3,596 ft)Max. depth4,198 m (13,773 ft)Water volume660,000 km3 (158,000…

فايكينغ 2   المشغل ناسا  المصنع مختبر الدفع النفاث،  ومارتن ماريتا  تاريخ الإطلاق 9 سبتمبر 1975[1]  موقع الإطلاق مجمع إطلاق الفضاء 41 في محطة كيب كانافيرال للقوات الجوية[1]  تاريخ الهبوط 3 سبتمبر 1976  موقع الهبوط المريخ  الموقع الإلكتروني الموقع الرسمي…

Internet Archive TipoONG Fondazione1996 Sede centrale San Francisco Area di azionePreservazione digitale PresidenteBrewster Kahle Mottouniversal access to all knowledge Sito web Modifica dati su Wikidata · Manuale Internet Archivesito webLogo URLarchive.org/ Tipo di sitoBiblioteca digitale LinguaInglese Registrazionefacoltativa Scopo di lucroNo Creato daBrewster Kahle Lanciomaggio 1996 Stato attualeattivo Sloganuniversal access to all knowledge Modifica dati su Wikidata · Manuale Int…

العلاقات التنزانية الجورجية تنزانيا جورجيا   تنزانيا   جورجيا تعديل مصدري - تعديل   العلاقات التنزانية الجورجية هي العلاقات الثنائية التي تجمع بين تنزانيا وجورجيا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه المقارنة …

Cuhon Administration Pays France Région Nouvelle-Aquitaine Département Vienne Arrondissement Poitiers Intercommunalité Communauté de communes du Haut-Poitou Maire Mandat Philippe Garanger 2020-2026 Code postal 86110 Code commune 86089 Démographie Gentilé Cuhonais Populationmunicipale 387 hab. (2021 ) Densité 24 hab./km2 Géographie Coordonnées 46° 45′ 34″ nord, 0° 05′ 50″ est Altitude Min. 93 mMax. 126 m Superficie 16,34 km…

Last NightSutradaraMassy TadjedinProduserBuddy Enright (Executive)Christophe RiandeeMassy TadjedinNick WechslerDitulis olehMassy TadjedinPemeranKeira KnightleySam WorthingtonEva MendesGuillaume CanetStephanie RomanovPenata musikClint MansellSinematograferPeter DemingPenyuntingSusan E. MorseDistributorGaumontMiramax Films (USA)Tanggal rilis 18 September 2010 (2010-09-18) (TIFF) 16 Februari 2011 (2011-02-16) (France) 6 Mei 2011 (2011-05-06) (United States) Durasi92…

Location of Union Parish in Louisiana This is a list of the National Register of Historic Places listings in Union Parish, Louisiana. This is intended to be a complete list of the properties on the National Register of Historic Places in Union Parish, Louisiana, United States. The locations of National Register properties for which the latitude and longitude coordinates are included below, may be seen in a map.[1] There are 11 properties listed on the National Register in the parish. …

Piala Liga Inggris 1992–19931992–93 Football League CupNegara Inggris WalesTanggal penyelenggaraan18 Agustus 1992 s.d. 18 April 1993Jumlah peserta92Juara bertahanManchester UnitedJuaraArsenal(gelar ke-2)Tempat keduaSheffield WednesdayPencetak gol terbanyakIan Wright(5 gol)← 1991–1992 1993–1994 → Piala Liga Inggris 1992–1993 adalah edisi ke-33 penyelenggaraan Piala Liga Inggris, sebuah kompetisi dengan sistem gugur untuk 92 tim terbaik di Inggris. Edisi ini dimenangkan ole…

Thomas Meißner Informasi pribadiNama lengkap Thomas MeißnerTanggal lahir 26 Maret 1991 (umur 33)Tempat lahir Schweinfurt, JermanTinggi 191 m (626 ft 7+1⁄2 in)Posisi bermain BekInformasi klubKlub saat ini MSV DuisburgNomor 25Karier junior FC Blau-Weiß Donnersdorf0000–2006 1. FC Schweinfurt 052006–2009 TSV 1860 München2009–2010 1. FSV Mainz 05Karier senior*Tahun Tim Tampil (Gol)2010–2012 1. FSV Mainz 05 II 63 (3)2012–2014 Borussia Dortmund II 63 (1)2014– M…

Funiculaire au sommet de Charlannes Le Funiculaire de la Bourboule a fonctionné dans cette ville entre 1902 et 1958. La construction était due à l'initiative de Jean Claret[1], ingénieur et entrepreneur Lyonnais. Un tramway à traction électrique (Jean Claret) reliait le centre-ville à La gare basse du funiculaire entre 1902 et 1910. La ligne La Bourboule - Sommet de Charlannes (587 mètres de long): ouverture 1902[1]; La gare basse du funiculaire était reliée au centre de la ville …

Disambiguazione – Se stai cercando altri significati, vedi Basilicata (disambigua). Basilicataregione a statuto ordinarioRegione Basilicata (dettagli) (dettagli) Basilicata – VedutaLa Basilicata vista dal satellite LocalizzazioneStato Italia AmministrazioneCapoluogoPotenza PresidenteVito Bardi (FI) dal 16-04-2019 Data di istituzione1948[1] TerritorioCoordinatedel capoluogo40°38′21″N 15°48′19″E / 40.639167°N 15.805278°E40.639167; 15.805278…

Assedio di Danzica del 1308parte delle Guerre polacco-teutonicheLa Polonia nel 1300 alle porte della conquista avvenuta dai teutonici otto anni dopoData13 novembre 1308 LuogoDanzica EsitoConquista dell'ordine della città a cui seguì un massacro degli abitanti, evento che portò a una prosecuzione del conflitto polacco-teutonico per i due secoli successivi Modifiche territorialiLa Pomerelia passa in mano teutonica e, solo nominalmente, soggetta alla Polonia: quest'ultima perde l'accesso al mar …

Questa voce sull'argomento stagioni delle società calcistiche italiane è solo un abbozzo. Contribuisci a migliorarla secondo le convenzioni di Wikipedia. Segui i suggerimenti del progetto di riferimento. Voce principale: Unione Sportiva Messinese. U.S. MessineseStagione 1925-1926Sport calcio Squadra Messinese Allenatore Gottardi Presidente Giovanni Vento, Augusto Salvato Prima Divisione2º posto nel girone siciliano (per peggior differenza reti) e 5º posto nel girone A delle semifin…

Bupati IndramayuPetahanaNina Agustinasejak 26 Februari 2021Masa jabatan5 tahun dan dapat dipilih kembali untuk satu kali masa jabatanPejabat pertamaRaden SingalodraWakilWakil Bupati IndramayuSitus webindramayukab.go.id Berikut ini adalah artikel tentang daftar bupati Indramayu dari tahun 1900. No Bupati Mulai menjabat Akhir menjabat Prd. Wakil Bupati ket 1 Raden Singalodra (Wiralodra I) 1 [ket. 1] 2 Raden Wirapati (Wiralodra II) 2 3 Raden Sawedi (Wiralodra III) 3 4 Raden Banggala (W…

Kembali kehalaman sebelumnya