-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathMoves.h
264 lines (199 loc) · 5.3 KB
/
Moves.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
DDS, a bridge double dummy solver.
Copyright (C) 2006-2014 by Bo Haglund /
2014-2018 by Bo Haglund & Soren Hein.
See LICENSE and README.
*/
#ifndef DDS_MOVES_H
#define DDS_MOVES_H
#include <iostream>
#include <fstream>
#include <string>
#include "dds.h"
#include "../include/dll.h"
using namespace std;
enum MGtype
{
MG_NT0 = 0,
MG_TRUMP0 = 1,
MG_NT_VOID1 = 2,
MG_TRUMP_VOID1 = 3,
MG_NT_NOTVOID1 = 4,
MG_TRUMP_NOTVOID1 = 5,
MG_NT_VOID2 = 6,
MG_TRUMP_VOID2 = 7,
MG_NT_NOTVOID2 = 8,
MG_TRUMP_NOTVOID2 = 9,
MG_NT_VOID3 = 10,
MG_TRUMP_VOID3 = 11,
MG_COMB_NOTVOID3 = 12,
MG_SIZE = 13
};
struct trickDataType
{
int playCount[DDS_SUITS];
int bestRank;
int bestSuit;
int bestSequence;
int relWinner;
int nextLeadHand;
};
class Moves
{
private:
int leadHand;
int leadSuit;
int currHand;
int currSuit;
int currTrick;
int trump;
int suit;
int numMoves;
int lastNumMoves;
struct trackType
{
int leadHand;
int leadSuit;
int playSuits[DDS_HANDS];
int playRanks[DDS_HANDS];
trickDataType trickData;
extCard move[DDS_HANDS];
int high[DDS_HANDS];
int lowestWin[DDS_HANDS][DDS_SUITS];
int removedRanks[DDS_SUITS];
};
trackType track[13];
trackType * trackp;
movePlyType moveList[13][DDS_HANDS];
moveType * mply;
MGtype lastCall[13][DDS_HANDS];
string funcName[MG_SIZE];
struct moveStatType
{
int count;
int findex;
int sumHits;
int sumLengths;
};
struct moveStatsType
{
int nfuncs;
moveStatType list[MG_SIZE];
};
moveStatType trickTable[13][DDS_HANDS];
moveStatType trickSuitTable[13][DDS_HANDS];
moveStatsType trickDetailTable[13][DDS_HANDS];
moveStatsType trickDetailSuitTable[13][DDS_HANDS];
moveStatsType trickFuncTable;
moveStatsType trickFuncSuitTable;
void WeightAllocTrump0(
const pos& tpos,
const moveType& bestMove,
const moveType& bestMoveTT,
const relRanksType thrp_rel[]);
void WeightAllocNT0(
const pos& tpos,
const moveType& bestMove,
const moveType& bestMoveTT,
const relRanksType thrp_rel[]);
void WeightAllocTrumpNotvoid1( const pos& tpos);
void WeightAllocNTNotvoid1(const pos& tpos);
void WeightAllocTrumpVoid1(const pos& tpos);
void WeightAllocNTVoid1(const pos& tpos);
void WeightAllocTrumpNotvoid2(const pos& tpos);
void WeightAllocNTNotvoid2(const pos& tpos);
void WeightAllocTrumpVoid2(const pos& tpos);
void WeightAllocNTVoid2(const pos& tpos);
void WeightAllocCombinedNotvoid3(const pos& tpos);
void WeightAllocTrumpVoid3(const pos& tpos);
void WeightAllocNTVoid3(const pos& tpos);
void GetTopNumber(
const int ris,
const int prank,
int& topNumber,
int& mno) const;
int RankForcesAce(int cards4th) const;
typedef void (Moves::*WeightPtr)(const pos& tpos);
WeightPtr WeightList[16];
inline bool WinningMove(
const moveType& mvp1,
const extCard& mvp2,
const int trump) const;
string PrintMove(const movePlyType& mply) const;
void MergeSort();
void UpdateStatsEntry(
moveStatsType& stat,
const int findex,
const int hit,
const int len) const;
string AverageString(const moveStatType& statp) const;
string FullAverageString(const moveStatType& statp) const;
string PrintTrickTable(const moveStatType tablep[][DDS_HANDS]) const;
string PrintFunctionTable(const moveStatsType& tablep) const;
public:
Moves();
~Moves() = default;
void Init(
const int tricks,
const int relStartHand,
const int initialRanks[],
const int initialSuits[],
const unsigned short rankInSuit[DDS_HANDS][DDS_SUITS],
const int trump,
const int leadHand);
void Reinit(
const int tricks,
const int leadHand);
int MoveGen0(
const int tricks,
const pos& tpos,
const moveType& bestMove,
const moveType& bestMoveTT,
const relRanksType thrp_rel[]);
int MoveGen123(
const int tricks,
const int relHand,
const pos& tpos);
int GetLength(
const int trick,
const int relHand) const;
void MakeSpecific(
const moveType& mply,
const int trick,
const int relHand);
moveType const * MakeNext(
const int trick,
const int relHand,
const unsigned short winRanks[DDS_SUITS]);
moveType const * MakeNextSimple(
const int trick,
const int relHand);
void Step(
const int tricks,
const int relHand);
void Rewind(
const int tricks,
const int relHand);
void Purge(
const int tricks,
const int relHand,
const moveType forbiddenMoves[]);
void Reward(
const int trick,
const int relHand);
const trickDataType& GetTrickData(const int tricks);
void Sort(
const int tricks,
const int relHand);
string PrintMoves(
const int trick,
const int relHand) const;
void RegisterHit(
const int tricks,
const int relHand);
string TrickToText(const int trick) const;
void PrintTrickStats(ofstream& fout) const;
void PrintTrickDetails(ofstream& fout) const;
void PrintFunctionStats(ofstream& fout) const;
};
#endif