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

Function constructDBKey

Rapfi/database/dbclient.cpp:333–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

331namespace Database {
332
333DBKey constructDBKey(const Board &board, Rule rule, TransformType *transType)
334{
335 DBKey key[TRANS_NB];
336 StonePos whiteStones[TRANS_NB][MAX_MOVES];
337 for (int trans = IDENTITY; trans < TRANS_NB; trans++) {
338 key[trans].rule = rule;
339 key[trans].boardWidth = board.size();
340 key[trans].boardHeight = board.size();
341 key[trans].sideToMove = board.sideToMove();
342 key[trans].numBlackStones = 0;
343 key[trans].numWhiteStones = 0;
344 }
345
346 for (int ply = 0; ply < board.ply(); ply++) {
347 Pos move = board.getHistoryMove(ply);
348 if (move == Pos::PASS)
349 continue;
350
351 Color c = board.cell(move).piece;
352 if (c == BLACK) {
353 for (int trans = IDENTITY; trans < TRANS_NB; trans++) {
354 Pos transformedPos = applyTransform(move, board.size(), (TransformType)trans);
355 key[trans].stones[key[trans].numBlackStones++] = {transformedPos.x(),
356 transformedPos.y()};
357 }
358 }
359 else if (c == WHITE) {
360 for (int trans = IDENTITY; trans < TRANS_NB; trans++) {
361 Pos transformedPos = applyTransform(move, board.size(), (TransformType)trans);
362 whiteStones[trans][key[trans].numWhiteStones++] = {transformedPos.x(),
363 transformedPos.y()};
364 }
365 }
366 }
367
368 // Construct 8 symmetry database keys, and find the smallest one
369 int smallestIndex = 0;
370
371 for (int trans = IDENTITY; trans < TRANS_NB; trans++) {
372 std::sort(key[trans].stones,
373 key[trans].stones + key[trans].numBlackStones,
374 std::less<StonePos>());
375 std::copy(whiteStones[trans],
376 whiteStones[trans] + key[trans].numWhiteStones,
377 key[trans].stones + key[trans].numBlackStones);
378 std::sort(key[trans].stones + key[trans].numBlackStones,
379 key[trans].stones + key[trans].numBlackStones + key[trans].numWhiteStones,
380 std::less<StonePos>());
381
382 if (trans != smallestIndex && key[trans] < key[smallestIndex])
383 smallestIndex = trans;
384 }
385
386 if (transType)
387 *transType = static_cast<TransformType>(smallestIndex);
388
389 return key[smallestIndex];
390}

Callers 10

recursiveDeleteChildrenFunction · 0.85
queryMethod · 0.85
queryBoardTextsMethod · 0.85
setBoardTextMethod · 0.85
saveMethod · 0.85
delMethod · 0.85
copyDatabasePathToRootFunction · 0.85
copyDatabaseBranchFunction · 0.85
importLibToDatabaseFunction · 0.85
databaseMethod · 0.85

Calls 8

applyTransformFunction · 0.85
copyFunction · 0.85
plyMethod · 0.80
getHistoryMoveMethod · 0.80
xMethod · 0.80
yMethod · 0.80
sizeMethod · 0.45
sideToMoveMethod · 0.45

Tested by

no test coverage detected