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

Function toSmallestDBKey

Rapfi/database/dbclient.cpp:392–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392void toSmallestDBKey(DBKey &key, TransformType *transType)
393{
394 DBKey transformedKeys[TRANS_NB - 1];
395 int smallestIndex = 0;
396 DBKey *smallestKey = &key;
397
398 // Construct 8 symmetry database keys, and find the smallest one
399 for (int trans = IDENTITY + 1; trans < TRANS_NB; trans++) {
400 DBKey &transKey = transformedKeys[trans - 1];
401 transKey.rule = key.rule;
402 transKey.boardWidth = key.boardWidth;
403 transKey.boardHeight = key.boardHeight;
404 transKey.sideToMove = key.sideToMove;
405 transKey.numBlackStones = key.numBlackStones;
406 transKey.numWhiteStones = key.numWhiteStones;
407
408 size_t numStones = 0;
409 for (const StonePos *pos = key.blackStonesBegin(); pos < key.whiteStonesEnd(); pos++) {
410 Pos originPos {pos->x, pos->y};
411 Pos transformedPos = applyTransform(originPos, key.boardWidth, (TransformType)trans);
412 transKey.stones[numStones++] = {transformedPos.x(), transformedPos.y()};
413 }
414
415 std::sort(transKey.stones,
416 transKey.stones + transKey.numBlackStones,
417 std::less<StonePos>());
418 std::sort(transKey.stones + transKey.numBlackStones,
419 transKey.stones + transKey.numBlackStones + transKey.numWhiteStones,
420 std::less<StonePos>());
421
422 if (transKey < *smallestKey)
423 smallestIndex = trans, smallestKey = &transKey;
424 }
425
426 // Copy smallest index back to the key
427 if (smallestIndex > 0)
428 key = *smallestKey;
429
430 if (transType)
431 *transType = static_cast<TransformType>(smallestIndex);
432}
433
434bool checkOverwrite(const DBRecord &oldRecord,
435 const DBRecord &newRecord,

Callers 1

iterateParentKeysFunction · 0.85

Calls 5

applyTransformFunction · 0.85
xMethod · 0.80
yMethod · 0.80
blackStonesBeginMethod · 0.45
whiteStonesEndMethod · 0.45

Tested by

no test coverage detected