]> git.sesse.net Git - stockfish/blob - src/book.h
Use pointers instead of array indices in MovePicker
[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-2009 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 : private std::ifstream {
56 public:
57   ~Book();
58   void open(const std::string& fName);
59   void close();
60   const std::string file_name() const;
61   Move get_move(const Position& pos);
62
63 private:
64   Book& operator>>(uint64_t& n) { n = read_integer(8); return *this; }
65   Book& operator>>(uint16_t& n) { n = (uint16_t)read_integer(2); return *this; }
66   void operator>>(BookEntry& e) { *this >> e.key >> e.move >> e.count >> e.n >> e.sum; }
67
68   uint64_t read_integer(int size);
69   void read_entry(BookEntry& e, int n);
70   int find_key(uint64_t key);
71
72   std::string fileName;
73   int bookSize;
74 };
75
76
77 ////
78 //// Global variables
79 ////
80
81 extern Book OpeningBook;
82
83
84 #endif // !defined(BOOK_H_INCLUDED)