]> git.sesse.net Git - stockfish/blob - src/tt.h
f39d37dd4e664b3e865d7baa592fb20540eaae3e
[stockfish] / src / tt.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
5   Glaurung is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9   
10   Glaurung is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14   
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #if !defined(TT_H_INCLUDED)
21 #define TT_H_INCLUDED
22
23 ////
24 //// Includes
25 ////
26
27 #include "depth.h"
28 #include "position.h"
29 #include "value.h"
30
31
32 ////
33 //// Types
34 ////
35
36 /// The TTEntry class is the class of transposition table entries.
37
38 class TTEntry {
39
40 public:
41   TTEntry();
42   TTEntry(Key k, Value v, ValueType t, Depth d, Move m, int generation);
43   Key key() const;
44   Depth depth() const;
45   Move move() const;
46   Value value() const;
47   ValueType type() const;
48   int generation() const;
49
50 private:  
51   Key key_;
52   uint32_t data;
53   int16_t value_;
54   int16_t depth_;
55 };
56
57
58 /// The transposition table class.  This is basically just a huge array
59 /// containing TTEntry objects, and a few methods for writing new entries
60 /// and reading new ones.
61
62 class TranspositionTable {
63
64 public:
65   TranspositionTable(unsigned mbSize);
66   ~TranspositionTable();
67   void set_size(unsigned mbSize);
68   void clear();
69   void store(const Position &pos, Value v, Depth d, Move m, ValueType type);
70   bool retrieve(const Position &pos, Value *value, Depth *d, Move *move,
71                 ValueType *type) const;
72   void new_search();
73   void insert_pv(const Position &pos, Move pv[]);
74   int full();
75
76 private:
77   unsigned size;
78   int writes;
79   TTEntry* entries;
80   uint8_t generation;
81 };
82
83
84 ////
85 //// Constants and variables
86 ////
87
88 // Default transposition table size, in megabytes:
89 const int TTDefaultSize = 32;
90
91
92 #endif // !defined(TT_H_INCLUDED)