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