zobrist hashing
This commit is contained in:
@ -2,9 +2,6 @@
|
||||
#include <stdint.h>
|
||||
#include <chess/types.h>
|
||||
|
||||
bool bitsetGet(uint_least64_t bitset, uint_least8_t i);
|
||||
uint_least64_t bitsetClear(uint_least64_t bitset, uint_least8_t i);
|
||||
uint_least64_t bitsetSet(uint_least64_t bitset, uint_least8_t i);
|
||||
bool bitboardGet(const uint_least64_t *board, struct piece_t piece, uint_least8_t i);
|
||||
uint_least64_t bitboardGetMask(const uint_least64_t *board, struct piece_t piece);
|
||||
void bitboardSetMask(uint_least64_t *board, struct piece_t piece, uint_least64_t value);
|
||||
@ -14,5 +11,3 @@ void bitboardClear(uint_least64_t *board, struct piece_t piece, uint_least8_t i)
|
||||
void bitboardSet(uint_least64_t *board, struct piece_t piece, uint_least8_t i);
|
||||
struct piece_t pieceAtField(const uint_least64_t *board, uint_least8_t i);
|
||||
struct gameState_t newGameState(uint_least64_t *board, char *FEN);
|
||||
uint_least8_t getFile(const uint_least8_t field);
|
||||
uint_least8_t getRank(const uint_least8_t field);
|
||||
|
||||
6
include/chess/bitset.h
Normal file
6
include/chess/bitset.h
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
bool bitsetGet(uint_least64_t bitset, uint_least8_t i);
|
||||
uint_least64_t bitsetClear(uint_least64_t bitset, uint_least8_t i);
|
||||
uint_least64_t bitsetSet(uint_least64_t bitset, uint_least8_t i);
|
||||
@ -17,6 +17,7 @@ enum spezialMoves {
|
||||
struct move_t {
|
||||
uint_least8_t src, dst, spezialMove;
|
||||
uint_least8_t srcPiece, dstPiece, capturedPiece;
|
||||
uint_least64_t hash;
|
||||
};
|
||||
|
||||
void genDirectionConsts();
|
||||
@ -25,7 +26,7 @@ uint_least8_t pieceValidMoves(struct gameState_t gameState, struct piece_t piece
|
||||
struct move_t *moves, bool promotion);
|
||||
|
||||
void undoMove(uint_least64_t *board, struct move_t move, bool color);
|
||||
struct gameState_t makeMove(struct gameState_t gameState, struct move_t move);
|
||||
struct gameState_t makeMove(struct gameState_t gameState, const struct move_t move);
|
||||
void initMagicTable();
|
||||
bool kingInCheck(const uint_least64_t *board, const bool color);
|
||||
uint_least8_t getBaseRankI(bool color);
|
||||
|
||||
@ -2,26 +2,29 @@
|
||||
#include <stdint.h>
|
||||
#include <chess/move.h>
|
||||
|
||||
#define fprintArray(file, printer, arr) \
|
||||
#define fprintArrayCustomLength(file, printer, arr, length) \
|
||||
do { \
|
||||
fprintf(file, "{"); \
|
||||
for(size_t i = 0; i < LENGTH(arr); ++i) { \
|
||||
for(size_t i = 0; i < length; ++i) { \
|
||||
printer(file, arr[i]); \
|
||||
if (i < LENGTH(arr) - 1) { \
|
||||
if (i < length - 1) { \
|
||||
fprintf(file, ", "); \
|
||||
} \
|
||||
} \
|
||||
fprintf(file, " }"); \
|
||||
} while(0)
|
||||
#define fprintArray(file, printer, arr) fprintArrayCustomLength(file, printer, arr, LENGTH(arr))
|
||||
|
||||
#define fdefineArray(file, declaration, printer, arr) \
|
||||
#define fdefineArrayCustomLength(file, declaration, printer, arr, length) \
|
||||
do { \
|
||||
fprintf(file, "%s[%zu] = ", declaration, LENGTH(arr)); \
|
||||
fprintArray(file, printer, arr); \
|
||||
fprintf(file, "%s[%zu] = ", declaration, length); \
|
||||
fprintArrayCustomLength(file, printer, arr, length); \
|
||||
fprintf(file, ";\n"); \
|
||||
} while(0)
|
||||
#define fdefineArray(file, declaration, printer, arr) fdefineArrayCustomLength(file, declaration, printer, arr, LENGTH(arr))
|
||||
|
||||
#define defineArray(declaration, printer, arr) fdefineArray(stdout, declaration, printer, arr)
|
||||
#define defineArrayCustomLength(declaration, printer, arr, length) fdefineArrayCustomLength(stdout, declaration, printer, arr, length)
|
||||
#define defineArray(declaration, printer, arr) defineArrayCustomLength(declaration, printer, arr, LENGTH(arr))
|
||||
|
||||
void printerll(FILE *file, long long num);
|
||||
void printerull(FILE *file, unsigned long long num);
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uint_least64_t rand_64();
|
||||
@ -53,6 +53,7 @@ struct castle_t {
|
||||
|
||||
struct gameState_t {
|
||||
uint_least64_t *board;
|
||||
uint_least64_t zobrist;
|
||||
bool color; // color to move
|
||||
struct castle_t canCastle[2];
|
||||
|
||||
|
||||
7
include/chess/util.h
Normal file
7
include/chess/util.h
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdint.h>
|
||||
#include <chess/types.h>
|
||||
|
||||
uint_least64_t rand_64();
|
||||
uint_least64_t zobristPieceI(struct piece_t piece, uint_least8_t field);
|
||||
uint_least8_t getFile(const uint_least8_t field);
|
||||
uint_least8_t getRank(const uint_least8_t field);
|
||||
16
include/chess/zobristConsts.h
Normal file
16
include/chess/zobristConsts.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef CHESS_ZOBRIST_CONSTS_H
|
||||
#define CHESS_ZOBRIST_CONSTS_H
|
||||
|
||||
#include "chess/types.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define ZOBRIST_CASTLE_LENGTH 2
|
||||
#define ZOBRIST_PIECE_LENGTH (TOTAL_BOARD_SIZE * 2 * PIECES_LENGTH)
|
||||
|
||||
extern const uint_least64_t ZOBRIST_PIECE[];
|
||||
extern const uint_least64_t ZOBRIST_BLACK_MOVE;
|
||||
extern const uint_least64_t ZOBRIST_SHORT_CASTLE[ZOBRIST_CASTLE_LENGTH];
|
||||
extern const uint_least64_t ZOBRIST_LONG_CASTLE[ZOBRIST_CASTLE_LENGTH];
|
||||
extern const uint_least64_t ZOBRIST_EN_PASSENT_FILE[BOARD_SIZE];
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user