-
Notifications
You must be signed in to change notification settings - Fork 0
/
endgame.h
155 lines (124 loc) · 3.97 KB
/
endgame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Quackle -- Crossword game artificial intelligence and analysis tool
* Copyright (C) 2005-2006 Jason Katz-Brown and John O'Laughlin.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef QUACKLE_ENDGAME_H
#define QUACKLE_ENDGAME_H
#include <fstream>
#include <math.h>
#include <vector>
#include "alphabetparameters.h"
#include "game.h"
namespace Quackle
{
struct EndgameMove
{
EndgameMove(const Move &_move) : move(_move) { }
Move move;
double optimistic;
double pessimistic;
double estimated;
bool outplay;
};
class EndgameMoveList : public vector<EndgameMove>
{
public:
static bool optimisticComparator(const EndgameMove &move1, const EndgameMove &move2);
};
class Endgame
{
public:
// constructs a new endgame solver
Endgame();
~Endgame();
// Find the best move in this position. Also initializes the
// move list, rack, resets numbers, and closes logfile.
void setPosition(const GamePosition &position);
// get access to the position that starts each playahead of the
// endgame; use to rechange rack or scores etcetera
GamePosition ¤tPosition();
const GamePosition ¤tPosition() const;
void setDispatch(ComputerDispatch *dispatch);
// If logfile is an empty string, logging is disabled.
// If logfile is the same logfile as currently set, nothing
// happens. If it is different, old logfile is closed if it
// was open. If append is false, this destroys file contents
// already in logfile.
void setLogfile(const string &logfile, bool append = true);
string logfile() const;
// append message to logfile if one is open
void logMessage(const UVString &message);
bool isLogging() const;
void closeLogfile();
// Set moves to include in solution.
void setIncludedMoves(const MoveList &moves);
// include only currently included moves that are within
// equityThreshold points below the best play and cap at
// maxNumberOfMoves
// void pruneTo(double equityThreshold, int maxNumberOfMoves);
// return a list of moves, sorted by estimated equity
MoveList moves(unsigned int nmoves);
// return the move list
const EndgameMoveList &endgameMoves() const;
// Return the best move
Move solve(int nestedness);
void reallyPlayOut(Move &move, int nestedness);
double disappoint(EndgameMove hope, double bestPessimistic);
protected:
void writeLogHeader();
void writeLogFooter();
UVOFStream m_logfileStream;
string m_logfile;
bool m_logfileIsOpen;
bool m_hasHeader;
UVString m_xmlIndent;
Game m_originalGame;
Game m_endgameGame;
ComputerDispatch *m_dispatch;
EndgameMoveList m_endgameMoves;
int m_nestedDisappointPlayNumber;
int m_subnestedDisappointPlayNumber;
int m_unnestedDisappointPlayNumber;
int m_nestedInitialPlayNumber;
int m_subnestedInitialPlayNumber;
int m_unnestedInitialPlayNumber;
};
inline GamePosition &Endgame::currentPosition()
{
return m_originalGame.currentPosition();
}
inline const GamePosition &Endgame::currentPosition() const
{
return m_originalGame.currentPosition();
}
inline string Endgame::logfile() const
{
return m_logfile;
}
inline bool Endgame::isLogging() const
{
return m_logfileIsOpen;
}
inline const EndgameMoveList &Endgame::endgameMoves() const
{
return m_endgameMoves;
}
}
UVOStream& operator<<(UVOStream& o, const Quackle::EndgameMove &move);
UVOStream& operator<<(UVOStream& o, const Quackle::EndgameMoveList &move);
#endif