typedef key -> #define key_t - can't use typedef, due to <sys/types.h>
This commit is contained in:
2
Makefile
2
Makefile
@@ -346,7 +346,7 @@ FEN_OBJS := $(PIECE_OBJS) fen.o position.o bitboard.o board.o \
|
|||||||
BB_OBJS := $(FEN_OBJS)
|
BB_OBJS := $(FEN_OBJS)
|
||||||
MOVEGEN_OBJS := $(BB_OBJS) move.o move-gen.o
|
MOVEGEN_OBJS := $(BB_OBJS) move.o move-gen.o
|
||||||
ATTACK_OBJS := $(MOVEGEN_OBJS)
|
ATTACK_OBJS := $(MOVEGEN_OBJS)
|
||||||
MOVEDO_OBJS := $(ATTACK_OBJS) move-do.o
|
MOVEDO_OBJS := $(ATTACK_OBJS) move-do.o hash.o
|
||||||
PERFT_OBJS := $(MOVEDO_OBJS) search.o misc.o
|
PERFT_OBJS := $(MOVEDO_OBJS) search.o misc.o
|
||||||
|
|
||||||
TEST := $(addprefix $(BINDIR)/,$(TEST))
|
TEST := $(addprefix $(BINDIR)/,$(TEST))
|
||||||
|
@@ -59,9 +59,9 @@ void zobrist_init(void)
|
|||||||
* - To verify incremental Zobrist calculation is correct
|
* - To verify incremental Zobrist calculation is correct
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
key zobrist_calc(pos_t *pos)
|
key_t zobrist_calc(pos_t *pos)
|
||||||
{
|
{
|
||||||
key key = 0;
|
key_t key = 0;
|
||||||
|
|
||||||
if (pos->turn == BLACK)
|
if (pos->turn == BLACK)
|
||||||
key ^= zobrist_turn;
|
key ^= zobrist_turn;
|
||||||
|
17
src/hash.h
17
src/hash.h
@@ -24,7 +24,7 @@
|
|||||||
#define HASH_SIZE_MIN 4
|
#define HASH_SIZE_MIN 4
|
||||||
#define HASH_SIZE_MAX 32768 /* 32Gb */
|
#define HASH_SIZE_MAX 32768 /* 32Gb */
|
||||||
|
|
||||||
typedef u64 key;
|
#define key_t u64 /* cannot use typedef for key_t */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hentry_t: hashtable bucket.
|
* hentry_t: hashtable bucket.
|
||||||
@@ -33,7 +33,7 @@ typedef u64 key;
|
|||||||
* 16 bytes in future, it should be updated to be exactly 32 bytes.
|
* 16 bytes in future, it should be updated to be exactly 32 bytes.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
key key; /* zobrist */
|
key_t key; /* zobrist */
|
||||||
union {
|
union {
|
||||||
u64 data;
|
u64 data;
|
||||||
struct {
|
struct {
|
||||||
@@ -81,9 +81,18 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
#define EP_ZOBRIST_IDX(ep) ( ( (ep) >> 3 ) | sq_file(ep) )
|
#define EP_ZOBRIST_IDX(ep) ( ( (ep) >> 3 ) | sq_file(ep) )
|
||||||
|
|
||||||
|
extern key_t zobrist_pieces[16][64];
|
||||||
|
extern key_t zobrist_castling[4 * 4 + 1];
|
||||||
|
extern key_t zobrist_turn; /* for black, XOR each ply */
|
||||||
|
extern key_t zobrist_ep[9]; /* 0-7: ep file, 8: SQUARE_NONE */
|
||||||
|
|
||||||
|
extern hasht_t hash_tt; /* main transposition table */
|
||||||
|
|
||||||
void zobrist_init(void);
|
void zobrist_init(void);
|
||||||
|
key_t zobrist_calc(pos_t *pos);
|
||||||
|
|
||||||
int hash_create(int Mb);
|
int hash_create(int Mb);
|
||||||
void hash_clear();
|
void hash_clear(void);
|
||||||
void hash_delete();
|
void hash_delete(void);
|
||||||
|
|
||||||
#endif /* HASH_H */
|
#endif /* HASH_H */
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "move.h"
|
#include "move.h"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
#include "move-do.h"
|
#include "move-do.h"
|
||||||
|
#include "hash.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move_do() - do move.
|
* move_do() - do move.
|
||||||
@@ -39,8 +40,12 @@
|
|||||||
* - castling
|
* - castling
|
||||||
* - en-passant
|
* - en-passant
|
||||||
* - captured piece (excl. en-passant)
|
* - captured piece (excl. en-passant)
|
||||||
|
* - tt hash values are updated for:
|
||||||
|
* - side-to-move
|
||||||
|
* - en-passant
|
||||||
|
* - castling rights.
|
||||||
*
|
*
|
||||||
* @return: pos.
|
* @return: updated pos.
|
||||||
*/
|
*/
|
||||||
pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
|
pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
|
||||||
{
|
{
|
||||||
@@ -57,6 +62,9 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
|
|||||||
piece_t new_piece = piece;
|
piece_t new_piece = piece;
|
||||||
int up = sq_up(us);
|
int up = sq_up(us);
|
||||||
|
|
||||||
|
/* update turn, reset castling and ep */
|
||||||
|
pos->key ^= zobrist_turn;
|
||||||
|
|
||||||
++pos->clock_50;
|
++pos->clock_50;
|
||||||
++pos->plycount;
|
++pos->plycount;
|
||||||
pos->en_passant = SQUARE_NONE;
|
pos->en_passant = SQUARE_NONE;
|
||||||
@@ -119,7 +127,8 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
|
|||||||
else if (from == rel_h1)
|
else if (from == rel_h1)
|
||||||
pos->castle = clr_oo(pos->castle, us);
|
pos->castle = clr_oo(pos->castle, us);
|
||||||
}
|
}
|
||||||
if (can_castle(pos->castle, them)) { /* do we save time with this test ? */
|
|
||||||
|
if (can_castle(pos->castle, them)) {
|
||||||
square_t rel_a8 = sq_rel(A8, us);
|
square_t rel_a8 = sq_rel(A8, us);
|
||||||
square_t rel_h8 = sq_rel(H8, us);
|
square_t rel_h8 = sq_rel(H8, us);
|
||||||
if (to == rel_a8)
|
if (to == rel_a8)
|
||||||
@@ -128,6 +137,7 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
|
|||||||
pos->castle = clr_oo(pos->castle, them);
|
pos->castle = clr_oo(pos->castle, them);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "brlib.h"
|
#include <brlib.h>
|
||||||
#include "bitops.h"
|
#include <bitops.h>
|
||||||
#include "struct-group.h"
|
#include <struct-group.h>
|
||||||
|
|
||||||
#include "chessdefs.h"
|
#include "chessdefs.h"
|
||||||
|
#include "hash.h"
|
||||||
#include "bitboard.h"
|
#include "bitboard.h"
|
||||||
#include "piece.h"
|
#include "piece.h"
|
||||||
#include "move.h"
|
#include "move.h"
|
||||||
@@ -41,6 +42,7 @@ typedef struct __pos_s {
|
|||||||
* This allows a memcpy on this data (to save/restore position state).
|
* This allows a memcpy on this data (to save/restore position state).
|
||||||
*/
|
*/
|
||||||
struct_group_tagged(state_s, state,
|
struct_group_tagged(state_s, state,
|
||||||
|
key_t key;
|
||||||
square_t en_passant;
|
square_t en_passant;
|
||||||
castle_rights_t castle;
|
castle_rights_t castle;
|
||||||
int clock_50;
|
int clock_50;
|
||||||
|
Reference in New Issue
Block a user