Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How Chess Engines Use Zobrist Hashes to Detect Repeated Positions

A Zobrist hash gives a chess engine a fast position fingerprint, but detecting repetition also requires move history and rule-aware comparisons.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Chess engines use a Zobrist hash as a compact fingerprint of a position, then compare that fingerprint with positions in the game or search history. The hash makes matching fast, but it cannot tell an engine by itself how often a position has occurred: the engine needs history, and it must include the game-state details that affect legal moves.

What a Zobrist hash represents

A chess position is more than the arrangement of pieces on the board. A Zobrist key combines pseudorandom values assigned to features that describe the current state. Stockfish’s implementation initializes keys for piece-square pairs, side to move, castling rights and en-passant files; other engines may choose different internal structures, but the key must cover the state relevant to their task. Stockfish position source

As an Amazon Associate I earn from qualifying purchases.

The result is a compact numeric fingerprint. It is useful for quickly identifying a position in structures such as a transposition table, where the same position can be reached by different move orders. It is not a unique proof of identity: hashes can collide, and a key is only as suitable as the state information included in it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How the key changes after a move

Zobrist hashing uses XOR to combine the keys for the active features. When a move changes the position, the engine can XOR out keys for features that are no longer present and XOR in keys for the new features. Since XORing the same value twice cancels it, the engine can update the key without rebuilding it from every square. Stockfish position source

  1. Start with the key for the current position.
  2. Remove the keys for changed features, such as a piece leaving its square or a castling right ending.
  3. Add keys for the resulting features, including the piece’s new square and any changed side-to-move or en-passant state.
  4. Use the updated key for lookups and, where needed, compare it with keys in the relevant history.

Why the board diagram is not enough

Under the FIDE Laws of Chess for over-the-board play, positions count as the same only when the same player has the move, the same kinds and colors of pieces occupy the same squares, and the possible moves for all pieces are the same. Thus, two identical-looking board diagrams can be different positions if one side has castling rights or an en-passant capture available and the other does not. FIDE Laws of Chess, effective 1 January 2023

That distinction is why a repetition detector must account for rule-relevant state rather than piece placement alone. It also shows why a repeated hash is not itself a draw decision: the game rules define which occurrences count and what procedure applies.

Why repetition detection needs history

A key describes the current state; it does not record how the game reached it. To determine whether a position has appeared before, an engine must consult prior positions or moves. The relevant scope may include the played game and the current search line, where the engine explores possible moves.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Stockfish’s UCI documentation recommends sending the position’s move list when setting up a position, because the move history is needed for correct threefold-repetition detection. A board snapshot alone cannot establish the number of previous occurrences. Stockfish UCI commands

How an engine can search for a recurrence

Scan or count prior keys

A straightforward approach is to compare the current key with earlier keys in the relevant history, or maintain counts of keys as moves are made and undone. This is conceptually simple, but the exact history window and bookkeeping must match the rules and the engine’s search needs.

Use a specialized lookup structure

Stockfish’s source comments that its repetition detection implements Marcel van Kervinck’s cuckoo algorithm, using two hash tables indexed with Zobrist hashes to find recurring positions. This is one implementation, not a universal requirement; engines can choose different history scans or data structures. Stockfish position source

Three different things to keep separate

  • Position key: a compact fingerprint of the current state and the rule-relevant features represented by the engine.
  • History: the earlier positions or moves needed to establish whether the current state has occurred before.
  • Draw rule: the governing chess rules that say when repetition can be claimed or becomes automatic.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What FIDE repetition rules mean for the engine

Under Article 9.2 of the FIDE Laws effective 1 January 2023, a player with the move may claim a draw when the same position is about to occur for the third time by indicating the intended move, or when it has just occurred for at least the third time. Article 9.6 makes the game drawn when the same position has appeared five times. These rules apply to over-the-board play under the cited Laws. FIDE Laws of Chess

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Consequently, an engine’s repetition check must do more than notice a matching fingerprint. It must use a history appropriate to the current game or search context, distinguish positions according to their move possibilities, and apply the relevant draw rule.

Best Value
Chessnut Move – Robotic Chessboard with Plastic Pieces, Self-Moving Pieces Simultaneously, Full Piece Recognition, Built-in Chess Engine, Voice Control & Video Integration
  • 🤖 SELF-MOVING CHESS ON A REAL BOARD - Chessnut Move pairs a wooden chessboard with plastic Automated pieces that automatically move across the board, bringing digital games to life.Move can reposition multiple pieces at once to reset games quickly or build study positions with less setup time.
  • 🎯 1 MM FULL PIECE RECOGNITION - Identifies every piece and its exact board position for accurate move tracking. A 10 Hz refresh rate and 0.1-second response support automated moves averaging under three seconds.
  • 🚂BUILT-IN STOCKFISH ENGINE - Play or practice against built-in engines such as Stockfish directly on Chessnut Move, with adjustable Elo difficulty and no phone, computer, or app required.
  • 📹VIDEO & ENDGAME IMPORT VIA APP - Connect to the Chessnut App to import positions or replay tutorial and tournament moves automatically on the physical board. Practice endgames, openings, and tactics with minimal setup.
  • 🔗ONLINE PLAY WITH AUTO RESPONSES - Connect through the Chessnut App to Chess-com, Lichess, and other supported platforms; your opponent's moves are automatically played on the physical board.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.