]> git.sesse.net Git - stockfish/blob - src/book.h
Prefer template to name decoration
[stockfish] / src / book.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
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.
9   
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.
14   
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/>.
17 */
18
19
20 /*
21   The code in this file is based on the opening book code in PolyGlot
22   by Fabien Letouzey.  PolyGlot is available under the GNU General
23   Public License, and can be downloaded from http://wbec-ridderkerk.nl
24 */
25
26
27 #if !defined(BOOK_H_INCLUDED)
28 #define BOOK_H_INCLUDED
29
30
31 ////
32 //// Includes
33 ////
34
35 #include <fstream>
36 #include <string>
37
38 #include "move.h"
39 #include "position.h"
40
41
42 ////
43 //// Types
44 ////
45
46 struct BookEntry {
47   uint64_t key;
48   uint16_t move;
49   uint16_t count;
50   uint16_t n;
51   uint16_t sum;
52 };
53
54 class Book {
55
56 public:
57   // Constructors
58   Book();
59
60   // Open and close book files
61   void open(const std::string &fName);
62   void close();
63
64   // Testing if a book is opened
65   bool is_open() const;
66
67   // The file name of the currently active book
68   const std::string file_name() const;
69
70   // Get a book move for a given position
71   Move get_move(const Position &pos) const;
72
73 private:
74   int find_key(uint64_t key) const;
75   void read_entry(BookEntry &entry, int n) const;
76
77   std::string fileName;
78   mutable std::ifstream bookFile;
79   int bookSize;
80 };
81
82
83 ////
84 //// Global variables
85 ////
86
87 extern Book OpeningBook;
88
89
90 #endif // !defined(BOOK_H_INCLUDED)