]> git.sesse.net Git - stockfish/blob - src/tt.h
Fix an assert due to a missing parentesis
[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 { return key_; }
44   Depth depth() const { return Depth(depth_); }
45   Move move() const { return Move(data & 0x7FFFF); }
46   Value value() const { return Value(value_); }
47   ValueType type() const { return ValueType((data >> 20) & 3); }
48   int generation() const { return (data >> 23); }
49
50 private:
51   Key key_;
52   uint32_t data;
53   int16_t value_;
54   int16_t depth_;
55 };
56
57 /// The transposition table class.  This is basically just a huge array
58 /// containing TTEntry objects, and a few methods for writing new entries
59 /// and reading new ones.
60
61 class TranspositionTable {
62
63 public:
64   TranspositionTable(unsigned mbSize);
65   ~TranspositionTable();
66   void set_size(unsigned mbSize);
67   void clear();
68   void store(const Position &pos, Value v, Depth d, Move m, ValueType type);
69   const TTEntry* retrieve(const Position &pos) const;
70   void new_search();
71   void insert_pv(const Position &pos, Move pv[]);
72   int full();
73
74 private:
75   inline TTEntry* first_entry(const Position &pos) const;
76
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)