A move needs 17 bits not 19
[qgit4/redivivus.git] / src / tt.h
blob31fc1fbce5f5a5801db869c86750028f2aa2c47e
1 /*
2 Stockfish, a UCI chess playing engine derived from Glaurung 2.1
3 Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
4 Copyright (C) 2008 Marco Costalba
6 Stockfish is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Stockfish is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #if !defined(TT_H_INCLUDED)
22 #define TT_H_INCLUDED
24 ////
25 //// Includes
26 ////
28 #include "depth.h"
29 #include "position.h"
30 #include "value.h"
33 ////
34 //// Types
35 ////
37 /// The TTEntry class is the class of transposition table entries.
39 class TTEntry {
41 public:
42 TTEntry();
43 TTEntry(Key k, Value v, ValueType t, Depth d, Move m, int generation);
44 Key key() const { return key_; }
45 Depth depth() const { return Depth(depth_); }
46 Move move() const { return Move(data & 0x1FFFF); }
47 Value value() const { return Value(value_); }
48 ValueType type() const { return ValueType((data >> 20) & 7); }
49 int generation() const { return (data >> 23); }
51 private:
52 Key key_;
53 uint32_t data;
54 int16_t value_;
55 int16_t depth_;
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.
62 class TranspositionTable {
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 TTEntry* retrieve(const Position &pos) const;
71 void new_search();
72 void insert_pv(const Position &pos, Move pv[]);
73 int full();
75 private:
76 inline TTEntry* first_entry(const Position &pos) const;
78 unsigned size;
79 int writes;
80 TTEntry* entries;
81 uint8_t generation;
85 ////
86 //// Constants and variables
87 ////
89 // Default transposition table size, in megabytes:
90 const int TTDefaultSize = 32;
93 #endif // !defined(TT_H_INCLUDED)