-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpeedTest.cpp
216 lines (180 loc) · 5.8 KB
/
SpeedTest.cpp
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
// Copyright Chris Welty
// All Rights Reserved
// This file is distributed subject to GNU GPL version 3. See the files
// GPLv3.txt and License.txt in the instructions subdirectory for details.
// test source file
#include <cstring>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include "core/Moves.h"
#include "core/QPosition.h"
#include "core/Cache.h"
#include "core/BitBoardTest.h"
#include "core/options.h"
#include "core/NodeStats.h"
#include "core/CalcParams.h"
#include "core/MPCStats.h"
#include "SpeedTest.h"
#include "Evaluator.h"
#include "PlayerComputer.h"
#include "Pos2.h"
using namespace std;
extern int iff;
//////////////////////////////////////////
// Test parameters
//////////////////////////////////////////
void SetupStuff(CMPCStats*& mpcs, CEvaluator*& eval, int& iPruneMidgame, int& iPruneEndgame) {
const int nLevels=0;
iPruneEndgame=iPruneMidgame=nLevels;
string fn(fnBaseDir);
fn+="coefficients/mpcJA_11.txt";
mpcs = new CMPCStats(fn.c_str(), 4);
eval = CEvaluator::FindEvaluator('J','4');
}
int roundsign(int n) {
if (n<-5)
return -1;
else
return n>5;
}
// flags for TestMidgameSpeed
const int kPrintTestHeader=1;
const int kPrintScrzebra=2;
const int kPrintValues=4;
const int kOnlyFinalRound=8;
void TestMidgameSpeed(int nEmpty, CHeightInfo hi, int nGames, int flags) {
double tRun, tTotal, geoMean;
CNodeStats start, end, start1, end1;
CCalcParamsFixedHeight pcp(hi);
CCalcParams *pcpOld;
CMVK mvk;
int nResult, nCorrect;
CComputerDefaults cd;
// setup computer
cd.fsPrint=-1;
CPlayerComputer computer(cd);
pcpOld=computer.pcp;
computer.pcp=&pcp;
// initialize stats
start.Read();
geoMean=tTotal=0;
nCorrect=0;
// print header info
if (flags&kPrintTestHeader) {
hi.SetNEmpty(nEmpty);
cout << "Testing " << (hi.IsKnownProbableSolve() ? "endgame" : "midgame") << " from " << nEmpty << " empties\n";
cout << "Height: " << hi << "\n";
}
else {
cout << hi << "\t" << nEmpty << "\t" << nGames << "\n";
}
// repeatedly test a game
const std::vector<COsGame> sgTest = LoadTestGames();
if (int(sgTest.size()) < nGames) {
std::cout << "insufficient games to test : wanted " << nGames << " but test games file only contains " << sgTest.size() << "\n";
return;
}
for (int iGame=0; iGame<nGames; iGame++) {
const COsGame& game=sgTest[iGame];
computer.Clear();
CQPosition pos = PositionFromEmpties(game, nEmpty);
if (flags&kPrintScrzebra) {
// print for scrzebra
char sBoard[NN+1], *pc;
pos.GetSBoard(sBoard);
for (pc=sBoard; *pc; pc++) {
switch(TextToValue(*pc)) {
case BLACK:
*pc='X';
break;
case WHITE:
*pc='O';
break;
default:
*pc='-';
break;
}
}
cout << sBoard << " " << (pos.BlackMove()?'X':'O') << " % Ntest position " << nEmpty << "." << game << "\n";
continue;
}
// get initial time
start1.Read();
// calc move and value
CSearchInfo si=computer.DefaultSearchInfo(pos.BlackMove(),CSearchInfo::kNeedMove+CSearchInfo::kNeedValue,1e6, 0);
si.SetPrintLevel(0);
computer.GetChosen(si, pos, mvk);
// calc timing
end1.Read();
tRun=(end1-start1).Seconds();
geoMean+=log(tRun);
tTotal+=tRun;
// check value for WLD
nResult=int(game.Result().dResult);
if (!pos.BlackMove())
nResult=-nResult;
if (roundsign(mvk.value)==Sign(nResult))
nCorrect++;
// print info
if (flags&kPrintValues) printf("%d\t",mvk.value);
cerr << "s";
// temporary test: Check cache afterwards
// computer.VerifyCache(si.iCache);
}
// print results
end.Read();
tRun=(end-start).Seconds();
if (flags&kPrintTestHeader) {
cout << "Run complete in " << tRun << "s; tTotal = " << tTotal << "; tAverage = " << tTotal/nGames;
cout << "\n";
cout << end-start << "\n";
}
else {
cout << nCorrect << "\t" << tTotal/nGames << "\n";
}
computer.pcp=pcpOld;
}
CQPosition PositionFromEmpties(const COsGame& game, int nEmpty) {
// setup board
CQPosition pos;
pos.Initialize();
size_t iMove;
for (iMove=0; pos.NEmpty()>nEmpty && iMove<game.ml.size(); iMove++) {
pos.MakeMove(game.ml[iMove].mv);
}
return pos;
}
void TestMidgameSpeeds(int nEmpty, CHeightInfo hiMax, int nGames, int flags) {
extern int iffMidgame;
iffMidgame=4;
CSearchInfo si(4,5,0,0,0,0,0,0);
CHeightInfo hi(1,0,0);
if (flags&kOnlyFinalRound)
hi=hiMax;
while (hi<=hiMax) {
TestMidgameSpeed(nEmpty, hi, nGames, flags);
hi.NextRound(nEmpty, si);
}
}
void TestLogStuff(int hMax) {
CHeightInfo hi(hMax,0,false);
CCalcParamsFixedHeight cp(hi);
CCalcParams *pcpOld;
CComputerDefaults cd;
CPlayerComputer computer(cd);
pcpOld=computer.pcp;
computer.pcp=&cp;
CMVK mvk;
CQPosition qpos("..................*O**....**O*....*OOO....OOOO......O...........", false);
CSearchInfo si=computer.DefaultSearchInfo(qpos.BlackMove(),CSearchInfo::kNeedMove+CSearchInfo::kNeedValue,1e6,0);
computer.GetChosen(si, qpos, mvk);
computer.pcp=pcpOld;
}
void TestMoveSpeed(int end_depth, int mid_depth) {
const int hEndgame=end_depth;
TestMidgameSpeed(hEndgame, CHeightInfo(hEndgame-hSolverStart,0,true), 1000, kPrintTestHeader);
const int hMidgame=mid_depth;
TestMidgameSpeed(36, CHeightInfo(hMidgame,4,false), 1000, kPrintTestHeader);
}