Yet another pop_1st_bit() optimization
[glaurung_clone.git] / src / tt.h
blobc1dd8508c2fadde864d8eb3a4932ca1b0812d3b1
1 /*
2 Glaurung, a UCI chess playing engine.
3 Copyright (C) 2004-2008 Tord Romstad
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.
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.
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/>.
20 #if !defined(TT_H_INCLUDED)
21 #define TT_H_INCLUDED
23 ////
24 //// Includes
25 ////
27 #include "depth.h"
28 #include "position.h"
29 #include "value.h"
32 ////
33 //// Types
34 ////
36 /// The TTEntry class is the class of transposition table entries.
38 class TTEntry {
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); }
50 private:
51 Key key_;
52 uint32_t data;
53 int16_t value_;
54 int16_t depth_;
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.
61 class TranspositionTable {
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();
74 private:
75 inline TTEntry* first_entry(const Position &pos) const;
77 unsigned size;
78 int writes;
79 TTEntry* entries;
80 uint8_t generation;
84 ////
85 //// Constants and variables
86 ////
88 // Default transposition table size, in megabytes:
89 const int TTDefaultSize = 32;
92 #endif // !defined(TT_H_INCLUDED)