Add Game::is_dangerous() for Futility Pruning
[purplehaze.git] / src / tt.h
blob78af08ed90621aaa02aa22a31527c12dbc967300
1 /* Copyright (C) 2007-2011 Vincent Ollivier
3 * Purple Haze is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * Purple Haze is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef TT_H
18 #define TT_H
20 #include <string>
22 #include "common.h"
23 #include "hashtable.h"
24 #include "move.h"
25 #include "zobrist.h"
27 class Transposition
29 private:
30 short value; // 2 bytes / 16 bits used
31 Move best_move; // 2 bytes / 16 bits used
32 unsigned char depth; // 1 byte / 8 bits used: depth < 256
33 Bound bound; // 1 byte / 2 bits used
35 public:
36 Transposition(int v, Bound b, int d, Move bm)
37 : value(v), best_move(bm), depth(d),
38 bound(b) {}
39 Transposition()
40 : value(0), best_move(Move()), depth(0),
41 bound(UNDEF_BOUND) {}
43 int get_value() const { return value; };
44 int get_depth() const { return depth; };
45 Bound get_bound() const { return bound; };
46 Move get_best_move() const { return best_move; };
48 bool is_empty() const {
49 return value == 0 &&
50 depth == 0 &&
51 bound == UNDEF_BOUND &&
52 best_move.is_null();
55 bool operator==(const Transposition& other) const {
56 return this->value == other.value &&
57 this->depth == other.depth &&
58 this->bound == other.bound &&
59 this->best_move == other.best_move;
61 bool operator!=(const Transposition& other) const {
62 return !(*this == other);
65 std::string to_string() const;
68 class Transpositions : public HashTable<Transposition>
70 private:
71 static const Transposition NULL_ENTRY;
73 public:
74 Transpositions(int n = TT_SIZE) : HashTable<Transposition>(n) {}
76 void save(Hash h, int v, Bound b, int d, Move bm) {
77 HashTable<Transposition>::save(h, Transposition(v, b, d, bm));
81 #endif /* !TT_H */