Class ZobristHashTable


  • public class ZobristHashTable
    extends java.lang.Object
    A variant of a efficient hashing-technique often used for chess and similar games.

    Replacement scheme explained here

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ARROW  
      static int EMPTY  
    • Constructor Summary

      Constructors 
      Constructor Description
      ZobristHashTable​(int size)
      Creates a hashtable with 2 slots for each index.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(HashTableElement newElement)
      Inserts the given Object into the hashtable according to the TwoDeep scheme.
      void clear()
      Deletes all elements.
      HashTableElement get​(long hash)
      Searches the hashtable for the given hash.
      HashTableElement get​(Board board)
      Searches the hashtable for the given board.
      long hash​(Board board)
      Hashes the given board according to the random table of this Zobrist instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZobristHashTable

        public ZobristHashTable​(int size)
        Creates a hashtable with 2 slots for each index.
        Parameters:
        size - size of the hashtable
    • Method Detail

      • add

        public void add​(HashTableElement newElement)
        Inserts the given Object into the hashtable according to the TwoDeep scheme.
        If the depth is greater than the first object, the first slot is replaced, otherwise it will be inserted into the second slot.
        This means the first slot is always the object with the highest depth, while the second slot is the most recently added object.
        Parameters:
        newElement - object that should be added to the hashtable
      • get

        public HashTableElement get​(long hash)
        Searches the hashtable for the given hash.
        Parameters:
        hash - hash value that serves as the index
        Returns:
        HashTableElement with the same hash value as the given hash
      • get

        public HashTableElement get​(Board board)
        Searches the hashtable for the given board.
        Parameters:
        board - board whose hash value serves as the index
        Returns:
        HashTableElement with the same hash value as the given board, null if no object with the same value was found
      • clear

        public void clear()
        Deletes all elements.
      • hash

        public long hash​(Board board)
        Hashes the given board according to the random table of this Zobrist instance.
        Parameters:
        board - board that shall be hashed
        Returns:
        hash value of board