forked from lightvector/KataGo
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdemoplay.cpp
More file actions
553 lines (476 loc) · 20.9 KB
/
Copy pathdemoplay.cpp
File metadata and controls
553 lines (476 loc) · 20.9 KB
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#include "../core/global.h"
#include "../core/fileutils.h"
#include "../core/fancymath.h"
#include "../core/makedir.h"
#include "../core/config_parser.h"
#include "../core/parallel.h"
#include "../core/timer.h"
#include "../core/test.h"
#include "../dataio/sgf.h"
#include "../dataio/poswriter.h"
#include "../dataio/files.h"
#include "../search/asyncbot.h"
#include "../program/setup.h"
#include "../program/playutils.h"
#include "../program/play.h"
#include "../command/commandline.h"
#include "../main.h"
#include <chrono>
using namespace std;
static void writeLine(
const Search* search, const BoardHistory& baseHist,
const vector<double>& winLossHistory, const vector<double>& scoreHistory, const vector<double>& scoreStdevHistory
) {
const Board& board = search->getRootBoard();
int nnXLen = search->nnXLen;
int nnYLen = search->nnYLen;
cout << board.x_size << " ";
cout << board.y_size << " ";
cout << nnXLen << " ";
cout << nnYLen << " ";
cout << baseHist.rules.komi << " ";
if(baseHist.isGameFinished) {
cout << PlayerIO::playerToString(baseHist.winner) << " ";
cout << baseHist.isResignation << " ";
cout << baseHist.finalWhiteMinusBlackScore << " ";
}
else {
cout << "-" << " ";
cout << "false" << " ";
cout << "0" << " ";
}
//Last move
Loc moveLoc = Board::NULL_LOC;
if(baseHist.moveHistory.size() > 0)
moveLoc = baseHist.moveHistory[baseHist.moveHistory.size()-1].loc;
cout << NNPos::locToPos(moveLoc,board.x_size,nnXLen,nnYLen) << " ";
cout << baseHist.moveHistory.size() << " ";
cout << board.numBlackCaptures << " ";
cout << board.numWhiteCaptures << " ";
for(int y = 0; y<board.y_size; y++) {
for(int x = 0; x<board.x_size; x++) {
Loc loc = Location::getLoc(x,y,board.x_size);
if(board.colors[loc] == C_BLACK)
cout << "x";
else if(board.colors[loc] == C_WHITE)
cout << "o";
else
cout << ".";
}
}
cout << " ";
vector<AnalysisData> buf;
if(!baseHist.isGameFinished) {
int minMovesToTryToGet = 0; //just get the default number
bool duplicateForSymmetries = true;
search->getAnalysisData(buf,minMovesToTryToGet,false,9,duplicateForSymmetries);
}
cout << buf.size() << " ";
for(int i = 0; i<buf.size(); i++) {
const AnalysisData& data = buf[i];
cout << NNPos::locToPos(data.move,board.x_size,nnXLen,nnYLen) << " ";
cout << data.numVisits << " ";
cout << data.winLossValue << " ";
cout << data.scoreMean << " ";
cout << data.scoreStdev << " ";
cout << data.policyPrior << " ";
}
vector<double> ownership = search->getAverageTreeOwnership();
for(int y = 0; y<board.y_size; y++) {
for(int x = 0; x<board.x_size; x++) {
int pos = NNPos::xyToPos(x,y,nnXLen);
cout << ownership[pos] << " ";
}
}
cout << winLossHistory.size() << " ";
for(int i = 0; i<winLossHistory.size(); i++)
cout << winLossHistory[i] << " ";
cout << scoreHistory.size() << " ";
assert(scoreStdevHistory.size() == scoreHistory.size());
for(int i = 0; i<scoreHistory.size(); i++)
cout << scoreHistory[i] << " " << scoreStdevHistory[i] << " ";
cout << endl;
}
static void initializeDemoGame(Board& board, BoardHistory& hist, Player& pla, Rand& rand, AsyncBot* bot) {
static const int numSizes = 9;
int sizes[numSizes] = {19,13,9,15,11,10,12,14,16};
int sizeFreqs[numSizes] = {240,18,12,6,2,1,1,1,1};
const int size = sizes[rand.nextUInt(sizeFreqs,numSizes)];
board = Board(size,size);
pla = P_BLACK;
hist.clear(board,pla,Rules::getTrompTaylorish(),0);
bot->setPosition(pla,board,hist);
if(size == 19) {
//Many games use a special opening
if(rand.nextBool(0.6)) {
auto g = [size](int x, int y) { return Location::getLoc(x,y,size); };
const Move nb = Move(Board::NULL_LOC, P_BLACK);
const Move nw = Move(Board::NULL_LOC, P_WHITE);
Player b = P_BLACK;
Player w = P_WHITE;
vector<vector<Move>> specialOpenings = {
//Sanrensei
{ Move(g(3,3), b), nw, Move(g(15,3), b), nw, Move(g(9,3), b) },
//Low Chinese
{ Move(g(3,3), b), nw, Move(g(16,3), b), nw, Move(g(10,2), b) },
//Low Chinese
{ Move(g(3,3), b), nw, Move(g(16,3), b), nw, Move(g(10,2), b) },
//High chinese
{ Move(g(3,3), b), nw, Move(g(16,3), b), nw, Move(g(10,3), b) },
//Low small chinese
{ Move(g(3,3), b), nw, Move(g(16,3), b), nw, Move(g(11,2), b) },
//Kobayashi
{ Move(g(3,3), b), Move(g(15,15), w), Move(g(16,3), b), nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(15,9), b) },
//Kobayashi
{ Move(g(3,3), b), Move(g(15,15), w), Move(g(16,3), b), nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(15,9), b) },
//Mini chinese
{ Move(g(3,3), b), Move(g(15,15), w), Move(g(15,2), b), nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(16,8), b) },
//Mini chinese
{ Move(g(3,3), b), Move(g(15,15), w), Move(g(15,2), b), nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(16,8), b) },
//Micro chinese
{ Move(g(3,3), b), Move(g(15,15), w), Move(g(15,2), b), nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(16,7), b) },
//Micro chinese with variable other corner
{ Move(g(15,2), b), Move(g(15,15), w), nb, nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(16,7), b) },
//Boring star points
{ Move(g(15,3), b), Move(g(15,15), w), nb, nw, Move(g(16,13), b), Move(g(13,16), w), Move(g(15,9), b) },
//High 3-4 counter approaches
{ Move(g(3,3), b), Move(g(15,16), w), Move(g(16,3), b), nw, Move(g(15,14), b), Move(g(14,3), w) },
//Double 3-3
{ Move(g(2,2), b), nw, Move(g(16,2), b) },
//Low enclosure
{ Move(g(2,3), b), nw, Move(g(4,2), b) },
//High enclosure
{ Move(g(2,3), b), nw, Move(g(4,3), b) },
//5-5 point
{ Move(g(4,4), b) },
//5-3 point
{ Move(g(2,4), b) },
//5-4 point
{ Move(g(3,4), b) },
//3-3 point
{ Move(g(2,2), b) },
//3-4 point far approach
{ Move(g(3,2), b), Move(g(2,5), w) },
//Tengen
{ Move(g(9,9), b) },
//2-2 point
{ Move(g(1,1), b) },
//Shusaku fuseki
{ Move(g(16,15), b), Move(g(3,16), w), Move(g(15,2), b), Move(g(14,16), w), nb, Move(g(16,4), w), Move(g(15,14), b) },
//Miyamoto fuseki
{ Move(g(16,13), b), Move(g(3,15), w), Move(g(13,2), b), nw, Move(g(9,16), b) },
//4-4 1-space low pincer - shared side
{ Move(g(15,15), b), Move(g(3,15), w), nb, nw, Move(g(5,16), b), Move(g(7,16), w) },
//4-4 2-space high pincer - shared side
{ Move(g(15,15), b), Move(g(3,15), w), nb, nw, Move(g(5,16), b), Move(g(8,15), w) },
//4-4 1-space low pincer - opponent side
{ Move(g(15,15), b), Move(g(3,15), w), nb, nw, Move(g(2,13), b), Move(g(2,11), w) },
//4-4 2-space high pincer - opponent side
{ Move(g(15,15), b), Move(g(3,15), w), nb, nw, Move(g(2,13), b), Move(g(3,10), w) },
//3-4 1-space low approach - shusaku kosumi and long extend
{ Move(g(15,15), b), Move(g(3,16), w), nb, nw, Move(g(2,14), b), Move(g(4,15), w), Move(g(2,10), b) },
//3-4 1-space low approach low pincer - opponent side
{ Move(g(15,15), b), Move(g(3,16), w), nb, nw, Move(g(2,14), b), Move(g(2,12), w) },
//3-4 2-space low approach high pincer - opponent side
{ Move(g(15,15), b), Move(g(3,16), w), nb, nw, Move(g(2,14), b), Move(g(3,11), w) },
//3-4 1-space high approach - opponent side
{ Move(g(15,15), b), Move(g(3,16), w), nb, nw, Move(g(3,14), b) },
//3-4 1-space high approach low pincer - opponent side
{ Move(g(15,15), b), Move(g(3,16), w), nb, nw, Move(g(3,14), b), Move(g(2,12), w) },
//3-4 2-space high approach high pincer - opponent side
{ Move(g(15,15), b), Move(g(3,16), w), nb, nw, Move(g(3,14), b), Move(g(3,11), w) },
//Orthodox
{ Move(g(3,3), b), nw, Move(g(15,2), b), nw, Move(g(16,4), b), Move(g(9,2), w) },
//Manchurian
{ Move(g(4,3), b), nw, Move(g(16,3), b), nw, Move(g(10,3), b) },
//Upper Manchurian
{ Move(g(4,4), b), nw, Move(g(16,4), b), nw, Move(g(10,4), b) },
//Great wall
{ Move(g(9,9), b), nw, Move(g(9,15), b), nw, Move(g(9,3), b), nw, Move(g(8,12), b), nw, Move(g(10,6), b) },
//Small wall
{ Move(g(9,8), b), nw, Move(g(8,11), b), nw, Move(g(10,5), b) },
//High approaches
{ Move(g(3,2), b), Move(g(3,4), w), Move(g(16,3), b), Move(g(14,3), w), Move(g(15,16), b), Move(g(15,14), w) },
//Black hole
{ Move(g(12,14), b), nw, Move(g(14,6), b), nw, Move(g(4,12), b), nw, Move(g(6,4), b) },
//Crosscut
{ Move(g(9,9), b), Move(g(9,10), w), Move(g(10,10), b), Move(g(10,9), w) },
//One-point jump center
{ Move(g(9,8), b), nw, Move(g(9,10), b) },
};
const vector<Move>& chosenOpening = specialOpenings[rand.nextUInt((int)specialOpenings.size())];
vector<vector<Move>> chosenOpenings;
for(int j = 0; j<8; j++) {
vector<Move> symmetric;
for(int k = 0; k<chosenOpening.size(); k++) {
Loc loc = chosenOpening[k].loc;
Player movePla = chosenOpening[k].pla;
if(loc == Board::NULL_LOC || loc == Board::PASS_LOC)
symmetric.emplace_back(loc,movePla);
else {
int x = Location::getX(loc,size);
int y = Location::getY(loc,size);
if(j & 1) x = size-1-x;
if(j & 2) y = size-1-y;
if(j & 4) std::swap(x,y);
symmetric.emplace_back(Location::getLoc(x,y,size),movePla);
}
}
chosenOpenings.push_back(symmetric);
}
for(int j = (int)chosenOpenings.size()-1; j>=1; j--) {
int r = rand.nextUInt(j+1);
vector<Move> tmp = chosenOpenings[j];
chosenOpenings[j] = chosenOpenings[r];
chosenOpenings[r] = tmp;
}
vector<Move> movesPlayed;
vector<Move> freeMovesPlayed;
vector<Move> specifiedMovesPlayed;
while(true) {
auto withinRadius1 = [size](Loc l0, Loc l1) {
if(l0 == Board::NULL_LOC || l1 == Board::NULL_LOC || l0 == Board::PASS_LOC || l1 == Board::PASS_LOC)
return false;
int x0 = Location::getX(l0,size);
int y0 = Location::getY(l0,size);
int x1 = Location::getX(l1,size);
int y1 = Location::getY(l1,size);
return std::abs(x0-x1) <= 1 && std::abs(y0-y1) <= 1;
};
auto symmetryIsGood = [&movesPlayed,&specifiedMovesPlayed,&freeMovesPlayed,&withinRadius1](const vector<Move>& moves) {
assert(movesPlayed.size() <= moves.size());
//Make sure the symmetry matches up to the desired point,
//and that free moves are not within radius 1 of any specified move
for(int j = 0; j<movesPlayed.size(); j++) {
if(moves[j].loc == Board::NULL_LOC) {
Loc actualLoc = movesPlayed[j].loc;
for(int k = 0; k<specifiedMovesPlayed.size(); k++) {
if(withinRadius1(specifiedMovesPlayed[k].loc,actualLoc))
return false;
}
}
else if(movesPlayed[j].loc != moves[j].loc)
return false;
}
//Make sure the next move will also not be within radius 1 of any free move.
if(movesPlayed.size() < moves.size()) {
Loc nextLoc = moves[movesPlayed.size()].loc;
for(int k = 0; k<freeMovesPlayed.size(); k++) {
if(withinRadius1(freeMovesPlayed[k].loc,nextLoc))
return false;
}
}
return true;
};
//Take the first good symmetry
vector<Move> goodSymmetry;
for(int i = 0; i<chosenOpenings.size(); i++) {
if(symmetryIsGood(chosenOpenings[i])) {
goodSymmetry = chosenOpenings[i];
break;
}
}
//If we have no further moves on that symmetry, we're done
if(movesPlayed.size() >= goodSymmetry.size())
break;
Move nextMove = goodSymmetry[movesPlayed.size()];
bool wasSpecified = true;
if(nextMove.loc == Board::NULL_LOC) {
wasSpecified = false;
Search* search = bot->getSearchStopAndWait();
NNResultBuf buf;
MiscNNInputParams nnInputParams;
nnInputParams.drawEquivalentWinsForWhite = search->searchParams.drawEquivalentWinsForWhite;
search->nnEvaluator->evaluate(board,hist,pla,nnInputParams,buf,false,false);
std::shared_ptr<NNOutput> nnOutput = std::move(buf.result);
double temperature = 0.8;
bool allowPass = false;
Loc banMove = Board::NULL_LOC;
Loc loc = PlayUtils::chooseRandomPolicyMove(nnOutput.get(), board, hist, pla, rand, temperature, allowPass, banMove);
nextMove.loc = loc;
}
//Make sure the next move is legal
if(!hist.isLegal(board,nextMove.loc,nextMove.pla))
break;
//Make the move!
hist.makeBoardMoveAssumeLegal(board,nextMove.loc,nextMove.pla,NULL);
pla = getOpp(pla);
hist.clear(board,pla,hist.rules,0);
bot->setPosition(pla,board,hist);
movesPlayed.push_back(nextMove);
if(wasSpecified)
specifiedMovesPlayed.push_back(nextMove);
else
freeMovesPlayed.push_back(nextMove);
bot->clearSearch();
writeLine(bot->getSearch(),hist,vector<double>(),vector<double>(),vector<double>());
std::this_thread::sleep_for(std::chrono::duration<double>(1.0));
} //Close while(true)
int numVisits = 20;
PlayUtils::adjustKomiToEven(bot->getSearchStopAndWait(),NULL,board,hist,pla,numVisits,OtherGameProperties(),rand);
double komi = hist.rules.komi + 0.3 * rand.nextGaussian();
komi = 0.5 * round(2.0 * komi);
hist.setKomi((float)komi);
bot->setPosition(pla,board,hist);
}
}
bot->clearSearch();
writeLine(bot->getSearch(),hist,vector<double>(),vector<double>(),vector<double>());
std::this_thread::sleep_for(std::chrono::duration<double>(2.0));
}
int MainCmds::demoplay(const vector<string>& args) {
Board::initHash();
ScoreValue::initTables();
Rand seedRand;
ConfigParser cfg;
string logFile;
string modelFile;
try {
KataGoCommandLine cmd("Self-play demo dumping status to stdout");
cmd.addConfigFileArg("","");
cmd.addModelFileArg();
cmd.addOverrideConfigArg();
TCLAP::ValueArg<string> logFileArg("","log-file","Log file to output to",false,string(),"FILE");
cmd.add(logFileArg);
cmd.parseArgs(args);
modelFile = cmd.getModelFile();
logFile = logFileArg.getValue();
cmd.getConfig(cfg);
}
catch (TCLAP::ArgException &e) {
cerr << "Error: " << e.error() << " for argument " << e.argId() << endl;
return 1;
}
Logger logger(&cfg);
logger.addFile(logFile);
logger.write("Engine starting...");
string searchRandSeed = Global::uint64ToString(seedRand.nextUInt64());
SearchParams params = Setup::loadSingleParams(cfg,Setup::SETUP_FOR_OTHER);
NNEvaluator* nnEval;
{
Setup::initializeSession(cfg);
const int expectedConcurrentEvals = params.numThreads;
const int defaultMaxBatchSize = -1;
const bool defaultRequireExactNNLen = false;
const bool disableFP16 = false;
const string expectedSha256 = "";
nnEval = Setup::initializeNNEvaluator(
modelFile,modelFile,expectedSha256,cfg,logger,seedRand,expectedConcurrentEvals,
NNPos::MAX_BOARD_LEN,NNPos::MAX_BOARD_LEN,defaultMaxBatchSize,defaultRequireExactNNLen,disableFP16,
Setup::SETUP_FOR_OTHER
);
}
logger.write("Loaded neural net");
const bool allowResignation = cfg.contains("allowResignation") ? cfg.getBool("allowResignation") : false;
const double resignThreshold = cfg.contains("allowResignation") ? cfg.getDouble("resignThreshold",-1.0,0.0) : -1.0; //Threshold on [-1,1], regardless of winLossUtilityFactor
const double resignScoreThreshold = cfg.contains("allowResignation") ? cfg.getDouble("resignScoreThreshold",-10000.0,0.0) : -10000.0;
const double searchFactorWhenWinning = cfg.contains("searchFactorWhenWinning") ? cfg.getDouble("searchFactorWhenWinning",0.01,1.0) : 1.0;
const double searchFactorWhenWinningThreshold = cfg.contains("searchFactorWhenWinningThreshold") ? cfg.getDouble("searchFactorWhenWinningThreshold",0.0,1.0) : 1.0;
//Check for unused config keys
cfg.warnUnusedKeys(cerr,&logger);
Setup::maybeWarnHumanSLParams(params,nnEval,NULL,cerr,&logger);
AsyncBot* bot = new AsyncBot(params, nnEval, &logger, searchRandSeed);
bot->setAlwaysIncludeOwnerMap(true);
Rand gameRand;
//Done loading!
//------------------------------------------------------------------------------------
logger.write("Loaded all config stuff, starting demo");
//Game loop
while(true) {
Player pla = P_BLACK;
Board baseBoard;
BoardHistory baseHist(baseBoard,pla,Rules::getTrompTaylorish(),0);
TimeControls tc;
initializeDemoGame(baseBoard, baseHist, pla, gameRand, bot);
bot->setPosition(pla,baseBoard,baseHist);
vector<double> recentWinLossValues;
vector<double> recentScores;
vector<double> recentScoreStdevs;
double callbackPeriod = 0.05;
std::function<void(const Search*)> callback = [&baseHist,&recentWinLossValues,&recentScores,&recentScoreStdevs](const Search* search) {
writeLine(search,baseHist,recentWinLossValues,recentScores,recentScoreStdevs);
};
//Move loop
int maxMovesPerGame = 1600;
for(int i = 0; i<maxMovesPerGame; i++) {
baseHist.endGameIfAllPassAlive(baseBoard);
if(baseHist.isGameFinished)
break;
callback(bot->getSearch());
double searchFactor =
//Speed up when either player is winning confidently, not just the winner only
std::min(
PlayUtils::getSearchFactor(searchFactorWhenWinningThreshold,searchFactorWhenWinning,params,recentWinLossValues,P_BLACK),
PlayUtils::getSearchFactor(searchFactorWhenWinningThreshold,searchFactorWhenWinning,params,recentWinLossValues,P_WHITE)
);
Loc moveLoc = bot->genMoveSynchronousAnalyze(pla,tc,searchFactor,callbackPeriod,callbackPeriod,callback);
bool isLegal = bot->isLegalStrict(moveLoc,pla);
if(moveLoc == Board::NULL_LOC || !isLegal) {
ostringstream sout;
sout << "genmove null location or illegal move!?!" << "\n";
sout << bot->getRootBoard() << "\n";
sout << "Pla: " << PlayerIO::playerToString(pla) << "\n";
sout << "MoveLoc: " << Location::toString(moveLoc,bot->getRootBoard()) << "\n";
logger.write(sout.str());
cerr << sout.str() << endl;
throw StringError("illegal move");
}
double winLossValue;
double expectedScore;
double expectedScoreStdev;
{
ReportedSearchValues values = bot->getSearch()->getRootValuesRequireSuccess();
winLossValue = values.winLossValue;
expectedScore = values.expectedScore;
expectedScoreStdev = values.expectedScoreStdev;
}
recentWinLossValues.push_back(winLossValue);
recentScores.push_back(expectedScore);
recentScoreStdevs.push_back(expectedScoreStdev);
bool resigned = false;
if(allowResignation) {
const BoardHistory hist = bot->getRootHist();
const Board initialBoard = hist.initialBoard;
//Play at least some moves no matter what
int minTurnForResignation = 1 + initialBoard.x_size * initialBoard.y_size / 6;
Player resignPlayerThisTurn = C_EMPTY;
if(winLossValue < resignThreshold && expectedScore < resignScoreThreshold)
resignPlayerThisTurn = P_WHITE;
else if(winLossValue > -resignThreshold && expectedScore > -resignScoreThreshold)
resignPlayerThisTurn = P_BLACK;
if(resignPlayerThisTurn == pla &&
bot->getRootHist().moveHistory.size() >= minTurnForResignation)
resigned = true;
}
if(resigned) {
baseHist.setWinnerByResignation(getOpp(pla));
break;
}
else {
//And make the move on our copy of the board
assert(baseHist.isLegal(baseBoard,moveLoc,pla));
baseHist.makeBoardMoveAssumeLegal(baseBoard,moveLoc,pla,NULL);
//If the game is over, skip making the move on the bot, to preserve
//the last known value of the search tree for display purposes
//Just immediately terminate the game loop
if(baseHist.isGameFinished)
break;
bool suc = bot->makeMove(moveLoc,pla);
assert(suc);
(void)suc; //Avoid warning when asserts are off
pla = getOpp(pla);
}
}
//End of game display line
writeLine(bot->getSearch(),baseHist,recentWinLossValues,recentScores,recentScoreStdevs);
//Wait a bit before diving into the next game
std::this_thread::sleep_for(std::chrono::seconds(10));
bot->clearSearch();
}
delete bot;
delete nnEval;
NeuralNet::globalCleanup();
ScoreValue::freeTables();
logger.write("All cleaned up, quitting");
return 0;
}