Merge branch 'release-2.1.0'
[purplehaze.git] / src / tt.h
bloba0e1c88e345f08afcf51e8be9fb39be159f7c78c
1 /* Copyright (C) 2007-2012 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"
26 class Transposition
28 private:
29 int16_t value_; // 2 bytes / 16 bits used
30 Move best_move_; // 2 bytes / 16 bits used
31 unsigned char depth_; // 1 byte / 8 bits used (depth < 256)
32 Bound bound_; // 1 byte / 2 bits used
34 public:
35 Transposition(int v, Bound b, int d, Move bm)
36 : value_(v), best_move_(bm), depth_(d),
37 bound_(b) {}
38 Transposition()
39 : value_(0), best_move_(Move()), depth_(0),
40 bound_(UNDEF_BOUND) {}
42 int value() const {
43 return value_;
45 int depth() const {
46 return depth_;
48 Bound bound() const {
49 return bound_;
51 Move best_move() const {
52 return best_move_;
55 bool is_empty() const {
56 return value_ == 0 &&
57 depth_ == 0 &&
58 bound_ == UNDEF_BOUND &&
59 best_move_.is_null();
62 bool operator==(const Transposition& other) const {
63 return this->value_ == other.value_ &&
64 this->depth_ == other.depth_ &&
65 this->bound_ == other.bound_ &&
66 this->best_move_ == other.best_move_;
68 bool operator!=(const Transposition& other) const {
69 return !(*this == other);
72 std::string to_string() const;
75 class Transpositions : public HashTable<Transposition>
77 private:
78 static const Transposition NULL_ENTRY;
80 public:
81 Transpositions(int n = TT_SIZE) : HashTable<Transposition>(n) {}
83 void save(Hash h, int v, Bound b, int d, Move bm) {
84 HashTable<Transposition>::save(h, Transposition(v, b, d, bm));
88 #endif /* !TT_H */