Cute Chess
0.1
projects
lib
src
openingbook.h
1
/*
2
This file is part of Cute Chess.
3
4
Cute Chess is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
Cute Chess is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#ifndef OPENING_BOOK_H
19
#define OPENING_BOOK_H
20
21
#include <QtGlobal>
22
#include <QMultiMap>
23
#include "board/genericmove.h"
24
25
class
QString
;
26
class
QDataStream
;
27
class
PgnGame
;
28
class
PgnStream
;
29
30
42
class
LIB_EXPORT
OpeningBook
43
{
44
public
:
46
enum
AccessMode
47
{
48
Ram
,
49
Disk
50
};
51
59
struct
Entry
60
{
62
Chess::GenericMove
move
;
68
quint16
weight
;
69
};
70
72
OpeningBook
(
AccessMode
mode = Ram);
74
virtual
~
OpeningBook
();
75
85
int
import
(
const
PgnGame
& pgn,
int
maxMoves);
95
int
import
(
PgnStream
& in,
int
maxMoves);
96
108
Chess::GenericMove
move(quint64 key)
const
;
109
111
QList<Entry>
entries(quint64 key)
const
;
112
117
bool
read(
const
QString
& filename);
118
123
bool
write(
const
QString
& filename)
const
;
124
125
126
protected
:
127
friend
LIB_EXPORT
QDataStream
& operator>>(
QDataStream
& in,
OpeningBook
* book);
128
friend
LIB_EXPORT
QDataStream
& operator<<(
QDataStream
& out,
const
OpeningBook
* book);
129
131
typedef
QMultiMap<quint64, Entry>
Map
;
132
134
virtual
int
entrySize()
const
= 0;
135
137
void
addEntry(
const
Entry
& entry, quint64 key);
138
145
virtual
Entry
readEntry(
QDataStream
& in, quint64* key)
const
= 0;
146
148
virtual
void
writeEntry(
const
Map::const_iterator& it,
149
QDataStream
& out)
const
= 0;
150
151
private
:
152
QList<Entry>
entriesFromDisk(quint64 key)
const
;
153
154
AccessMode
m_mode;
155
QString
m_filename;
156
Map
m_map;
157
};
158
165
extern
LIB_EXPORT
QDataStream
& operator>>(
QDataStream
& in,
OpeningBook
* book);
166
174
extern
LIB_EXPORT
QDataStream
&
operator<<
(
QDataStream
& out,
const
OpeningBook
* book);
175
176
#endif // OPENING_BOOK_H
PgnStream
A class for reading games in PGN format from a text stream.
Definition:
pgnstream.h:41
QDataStream
OpeningBook::Ram
Load the entire book to RAM.
Definition:
openingbook.h:48
OpeningBook::Map
QMultiMap< quint64, Entry > Map
Definition:
openingbook.h:131
PgnGame
A game of chess in PGN format.
Definition:
pgngame.h:51
OpeningBook::Entry::weight
quint16 weight
Definition:
openingbook.h:68
Chess::GenericMove
A chess move independent of chess variant or opening book format.
Definition:
genericmove.h:33
OpeningBook::Entry
An entry in the opening book.
Definition:
openingbook.h:59
QString
QList
OpeningBook::AccessMode
AccessMode
Definition:
openingbook.h:46
OpeningBook::Entry::move
Chess::GenericMove move
Definition:
openingbook.h:62
QCPVector2D::operator<<
QDebug operator<<(QDebug d, const QCPVector2D &vec)
Definition:
qcustomplot.h:441
QMultiMap< quint64, Entry >
OpeningBook
A collection of opening moves for chess.
Definition:
openingbook.h:42
Generated by
1.8.14