zobrist hashing

This commit is contained in:
2024-09-22 11:45:30 +02:00
parent 4d2a86c7b7
commit db958dcac1
21 changed files with 273 additions and 176 deletions

View File

@ -0,0 +1,24 @@
#include <stdint.h>
#include <chess/types.h>
#include <chess/generated/moveConsts.h>
#include <chess/bitset.h>
uint_least64_t slidingMovementMask(const uint_least8_t *direction, uint_least8_t directionLength,
uint_least8_t field, uint_least64_t blockMask) {
defineDirectionOffset;
const uint_least8_t *localDirectionOffset = DIRECTION_OFFSET + field * DIRECTION_LENGTH;
uint_least64_t movementMask = 0;
for(uint_least8_t j = 0; j < directionLength; ++j) {
const int_least8_t modifier = DIRECTION_MODIFIER[direction[j]];
for(uint_least8_t currentField = field + modifier, i = 0;
i < localDirectionOffset[direction[j]]; ++i, currentField += modifier) {
movementMask = bitsetSet(movementMask, currentField);
if(bitsetGet(blockMask, currentField)) break;
}
}
return movementMask;
}
uint_least64_t* getMagicAttackPtr(const uint_least64_t mask, const struct magic_t magic) {
return magic.attackTable + ((mask * magic.magicNumber) >> magic.shift);
}