2 Commits

Author SHA1 Message Date
00fc61020c "#define key_t" -> hkey_t type 2024-06-06 07:38:01 +02:00
06904f8a77 cleanup fetch-all.sh 2024-06-06 07:32:48 +02:00
5 changed files with 44 additions and 45 deletions

View File

@@ -1,53 +1,44 @@
#!/usr/bin/env bash
#
# Fetch all branches from remotes, and track missing ones.
#
# The value of variable ORIGIN is used for repository origin. If
# not set, the default is "origin".
origin=origin
default_origin=origin
declare -a remotes local_b
#declare -A aremotes
origin=${ORIGIN:-$default_origin}
declare -a local_b
declare -A alocal_b
# get remotes list
readarray -t remotes < <(git remote)
# fetch all remotes
git fetch --all
git fetch --all --tags
# fill associative array with remote
#for remote in "${remotes[@]}"; do
# aremotes["$remote"]=1
# echo doing git fetch -a "$remote"
#done
# get local branches
# get local branches, and build reverse associative array
readarray -t local_b < <(git for-each-ref --format='%(refname:short)' refs/heads/)
# build local ref array
for ref in "${local_b[@]}"; do
alocal_b[$ref]=1
done
# get origin branches
# get "origin" branches
readarray -t orig_b < <(git for-each-ref --format='%(refname:short)' \
refs/remotes/"$origin"/)
declare -p remotes
declare -p local_b orig_b
# find-out missing local branches and track them
# find-out missing local branches and track them.
# bugs:
# - We only check local branch existence, not tracking information correctness.
# - What about sub-branches ? Like remote/a and remote/a/b not being tracked ?
for remote_b in "${orig_b[@]}"; do
short=${remote_b#"$origin"/};
#echo "$remote_b -> $short ${alocal_b[$short]}"
# OR (??): short=${remote_b##*/}
if ! [[ -v alocal_b[$short] ]]; then
echo git branch --track "$short" "$remote_b"
# echo git branch: "$remote_b"
printf "local branch %s set to track %s.\n" "$short" "$remote_b"
git branch --track "$short" "$remote_b"
else
printf "skipping %s.\n" "$remote_b"
fi
done
echo git pull --all
#git remote | xargs -n 1 git fetch -a
git pull -a

View File

@@ -66,9 +66,9 @@ void zobrist_init(void)
*
* @return: @pos Zobrist key
*/
key_t zobrist_calc(pos_t *pos)
hkey_t zobrist_calc(pos_t *pos)
{
key_t key = 0;
hkey_t key = 0;
if (pos->turn == BLACK)
key ^= zobrist_turn;

View File

@@ -24,7 +24,7 @@
#define HASH_SIZE_MIN 4
#define HASH_SIZE_MAX 32768 /* 32Gb */
#define key_t u64 /* cannot use typedef for key_t */
typedef u64 hkey_t; /* cannot use typedef for key_t */
/**
* hentry_t: hashtable bucket.
@@ -33,7 +33,7 @@
* 16 bytes in future, it should be updated to be exactly 32 bytes.
*/
typedef struct {
key_t key; /* zobrist */
hkey_t key; /* zobrist */
union {
u64 data;
struct {
@@ -81,15 +81,15 @@ 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 hkey_t zobrist_pieces[16][64];
extern hkey_t zobrist_castling[4 * 4 + 1];
extern hkey_t zobrist_turn; /* for black, XOR each ply */
extern hkey_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);
hkey_t zobrist_calc(pos_t *pos);
#ifdef ZOBRIST_VERIFY
bool zobrist_verify(pos_t *pos);

View File

@@ -61,7 +61,7 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
piece_type_t ptype = PIECE(piece);
piece_t new_piece = piece;
int up = sq_up(us);
key_t key = pos->key;
hkey_t key = pos->key;
/* update key: switch turn, reset castling and ep */
key ^= zobrist_turn;
@@ -146,7 +146,7 @@ pos_t *move_do(pos_t *pos, const move_t move) //, state_t *state)
pos->castle = clr_oo(pos->castle, them);
}
/* update castle key */
/* update castling rights key */
key ^= zobrist_castling[pos->castle];
pos->key = key;
@@ -168,7 +168,7 @@ pos_t *move_do2(pos_t *pos, const move_t move, state_t *state)
piece_type_t ptype = PIECE(piece);
piece_t new_piece = piece;
int up = sq_up(us);
key_t key = pos->key;
hkey_t key = pos->key;
*state = pos->state; /* save irreversible changes */

View File

@@ -28,6 +28,13 @@
#include "move.h"
#include "board.h"
#define REPEAT_SIZE 1024
typedef struct {
hkey_t key[REPEAT_SIZE];
int moves;
} repeat_t;
typedef struct __pos_s {
u64 node_count; /* evaluated nodes */
int turn; /* WHITE or BLACK */
@@ -43,7 +50,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;
hkey_t key;
square_t en_passant;
castle_rights_t castle;
int clock_50;
@@ -57,6 +64,7 @@ typedef struct __pos_s {
piece_t board[BOARDSIZE];
bitboard_t bb[2][PIECE_TYPE_MAX]; /* bb[0][PAWN], bb[1][ALL_PIECES] */
square_t king[2]; /* dup with bb, faster retrieval */
repeat_t repeat; /* for repetition detection */
} pos_t;
typedef struct state_s state_t;