]> git.sesse.net Git - stockfish/blob - src/tt.h
Micro-optimize do_generate_pawn_checks()
[stockfish] / src / tt.h
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
5
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.
10
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.
15
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/>.
18 */
19
20
21 #if !defined(TT_H_INCLUDED)
22 #define TT_H_INCLUDED
23
24 ////
25 //// Includes
26 ////
27
28 #include "depth.h"
29 #include "position.h"
30 #include "value.h"
31
32
33 ////
34 //// Types
35 ////
36
37 /// The TTEntry class is the class of transposition table entries.
38
39 class TTEntry {
40
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 & 0x7FFFF); }
47   Value value() const { return Value(value_); }
48   ValueType type() const { return ValueType((data >> 20) & 3); }
49   int generation() const { return (data >> 23); }
50
51 private:
52   Key key_;
53   uint32_t data;
54   int16_t value_;
55   int16_t depth_;
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   const TTEntry* retrieve(const Position &pos) const;
71   void new_search();
72   void insert_pv(const Position &pos, Move pv[]);
73   int full();
74
75 private:
76   inline TTEntry* first_entry(const Position &pos) const;
77
78   unsigned size;
79   int writes;
80   TTEntry* entries;
81   uint8_t generation;
82 };
83
84
85 ////
86 //// Constants and variables
87 ////
88
89 // Default transposition table size, in megabytes:
90 const int TTDefaultSize = 32;
91
92
93 #endif // !defined(TT_H_INCLUDED)