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)
|
||||
MOVEGEN_OBJS := $(BB_OBJS) move.o move-gen.o
|
||||
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
|
||||
|
||||
TEST := $(addprefix $(BINDIR)/,$(TEST))
|
||||
|
@@ -59,9 +59,9 @@ void zobrist_init(void)
|
||||
* - 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)
|
||||
key ^= zobrist_turn;
|
||||
|
17
src/hash.h
17
src/hash.h
@@ -24,7 +24,7 @@
|
||||
#define HASH_SIZE_MIN 4
|
||||
#define HASH_SIZE_MAX 32768 /* 32Gb */
|
||||
|
||||
typedef u64 key;
|
||||
#define key_t u64 /* cannot use typedef for key_t */
|
||||
|
||||
/**
|
||||
* hentry_t: hashtable bucket.
|
||||
@@ -33,7 +33,7 @@ typedef u64 key;
|
||||
* 16 bytes in future, it should be updated to be exactly 32 bytes.
|
||||
*/
|
||||
typedef struct {
|
||||
key key; /* zobrist */
|
||||
key_t key; /* zobrist */
|
||||
union {
|
||||
u64 data;
|
||||
struct {
|
||||
@@ -81,9 +81,18 @@ typedef struct {
|
||||
*/
|
||||
#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);
|
||||
key_t zobrist_calc(pos_t *pos);
|
||||
|
||||
int hash_create(int Mb);
|
||||
void hash_clear();
|
||||
void hash_delete();
|
||||
void hash_clear(void);
|
||||
void hash_delete(void);
|
||||
|
||||
#endif /* HASH_H */
|
||||
|
@@ -23,6 +23,7 @@
|
||||
#include "move.h"
|
||||
#include "position.h"
|
||||
#include "move-do.h"
|
||||
#include "hash.h"
|
||||
|
||||
/**
|
||||
* move_do() - do move.
|
||||
@@ -39,8 +40,12 @@
|
||||
* - castling
|
||||
* - 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)
|
||||
{
|
||||
@@ -57,6 +62,9 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
|
||||
piece_t new_piece = piece;
|
||||
int up = sq_up(us);
|
||||
|
||||
/* update turn, reset castling and ep */
|
||||
pos->key ^= zobrist_turn;
|
||||
|
||||
++pos->clock_50;
|
||||
++pos->plycount;
|
||||
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)
|
||||
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_h8 = sq_rel(H8, us);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
@@ -16,11 +16,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "brlib.h"
|
||||
#include "bitops.h"
|
||||
#include "struct-group.h"
|
||||
#include <brlib.h>
|
||||
#include <bitops.h>
|
||||
#include <struct-group.h>
|
||||
|
||||
#include "chessdefs.h"
|
||||
#include "hash.h"
|
||||
#include "bitboard.h"
|
||||
#include "piece.h"
|
||||
#include "move.h"
|
||||
@@ -41,6 +42,7 @@ typedef struct __pos_s {
|
||||
* This allows a memcpy on this data (to save/restore position state).
|
||||
*/
|
||||
struct_group_tagged(state_s, state,
|
||||
key_t key;
|
||||
square_t en_passant;
|
||||
castle_rights_t castle;
|
||||
int clock_50;
|
||||
|
Reference in New Issue
Block a user