zobrist hashing
This commit is contained in:
24
src/common/postCodeGen/magic.c
Normal file
24
src/common/postCodeGen/magic.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user