]> git.sesse.net Git - stupid/blob - hash.h
Initial checkin for move to Git (no prior version history available).
[stupid] / hash.h
1 #ifndef _HASH_H
2 #define _HASH_H 1
3
4 #include "common.h"
5
6 /* Simple Zobrist hashing in a classic hash table */
7 struct hash_entry {
8         unsigned long long phash;
9         int score;
10         unsigned char depth, seldepth, best_from, best_to;
11         struct hash_entry *next;
12 };
13 struct hash_pawn_entry {
14         unsigned long long phash;
15         int pawn_score, king_safety;
16         struct hash_pawn_entry *next;
17 };
18
19 extern unsigned hash_used;
20
21 /* The inserter will never have more elements in the hash table than this (approx. 32MB) */
22 #define HASH_MAX_ELEMS (32000000 / sizeof(struct hash_entry))
23 // #define HASH_BUCKETS (HASH_MAX_ELEMS / 16)
24 #define HASH_BUCKETS 16384 /* better to have a power of two */
25 #define RHASH_BUCKETS 64
26 #define PHASH_BUCKETS 262144
27
28 extern struct hash_entry *transposition_table[HASH_BUCKETS];
29 extern struct hash_pawn_entry *pawn_eval_table[PHASH_BUCKETS];
30
31 void clear_hash(void);
32 void init_hash(void);
33
34 unsigned hash_position(const struct position * const p);
35 unsigned long long hash_position_pk(const struct position * const p);
36
37 // transposition table
38 bool lookup_hash(const struct position * const pos, unsigned long long phash, unsigned min_depth, unsigned min_seldepth, unsigned *ret_from, unsigned *ret_to, int *ret_score);
39 void insert_hash(const struct position * const pos, unsigned long long phash, unsigned depth, unsigned seldepth, unsigned from, unsigned to, int score);
40
41 // history table (threefold repetition code)
42 int lookup_record(unsigned long long phash);
43 void record_move(const struct position * const pos);
44
45 #ifdef PROFILE_HASHES
46 void record_lookup(unsigned hash_num, bool hit, unsigned chain_length);
47 void print_profile(unsigned hash_num);
48 #endif
49
50 #endif