MCPcopy Create free account
hub / github.com/dhbloo/rapfi / importLibToDatabase

Function importLibToDatabase

Rapfi/database/dbutils.cpp:316–427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

314}
315
316size_t importLibToDatabase(DBStorage &dbDst, std::istream &libStream, Rule rule, int boardSize)
317{
318 size_t writeCount = 0;
319
320 try {
321 Renlib::RenlibReader libReader(libStream);
322
323 auto callback = [&](const Board &board,
324 bool hasTag,
325 const std::string *text,
326 const std::string *comment) {
327 DBKey key = constructDBKey(board, rule);
328 DBRecord oldRecord, newRecord = {LABEL_NONE};
329 bool hasOldRecord = dbDst.get(key, oldRecord);
330
331 if (!text && !comment) {
332 // Write empty record if no record exists
333 if (!hasOldRecord) {
334 dbDst.set(key, newRecord, RECORD_MASK_LVDB);
335 writeCount++;
336 }
337
338 return;
339 }
340
341 if (text && text->size() > 0) {
342 const std::string &t = *text;
343 if (t[0] == 'W') {
344 newRecord.label = LABEL_WIN;
345 if (t.size() > 1) {
346 int mateStepFromRoot = std::atoi(t.c_str() + 1);
347 if (mateStepFromRoot > board.ply()) {
348 newRecord.value = mated_in(mateStepFromRoot - board.ply());
349 newRecord.setDepthBound(0, BOUND_EXACT);
350 }
351 }
352 }
353 else if (t[0] == 'L') {
354 newRecord.label = LABEL_LOSE;
355 if (t.size() > 1) {
356 int mateStepFromRoot = std::atoi(t.c_str() + 1);
357 if (mateStepFromRoot > board.ply()) {
358 newRecord.value = mate_in(mateStepFromRoot - board.ply());
359 newRecord.setDepthBound(0, BOUND_EXACT);
360 }
361 }
362 }
363 else if (t[0] == Config::DatabaseLibBlackWinMark && board.sideToMove() == BLACK) {
364 newRecord.label = LABEL_WIN;
365 }
366 else if (t[0] == Config::DatabaseLibWhiteWinMark && board.sideToMove() == WHITE) {
367 newRecord.label = LABEL_WIN;
368 }
369 else if (t[0] == Config::DatabaseLibBlackLoseMark && board.sideToMove() == BLACK) {
370 newRecord.label = LABEL_LOSE;
371 }
372 else if (t[0] == Config::DatabaseLibWhiteLoseMark && board.sideToMove() == WHITE) {
373 newRecord.label = LABEL_LOSE;

Callers 2

databaseMethod · 0.85
libToDatabaseFunction · 0.85

Calls 15

constructDBKeyFunction · 0.85
mated_inFunction · 0.85
mate_inFunction · 0.85
LegacyFileCPToUTF8Function · 0.85
checkOverwriteFunction · 0.85
DBRecordMaskEnum · 0.85
setMethod · 0.80
plyMethod · 0.80
setDepthBoundMethod · 0.80
getLastMoveMethod · 0.80
commentMethod · 0.80
setCommentMethod · 0.80

Tested by

no test coverage detected