Skip to content

Commit

Permalink
Cleanup (#694)
Browse files Browse the repository at this point in the history
No functional change

Bench: 30658368
  • Loading branch information
TerjeKir authored Nov 19, 2023
1 parent b5bb91d commit c000a56
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ CONSTR(1) InitDistance() {
}
}

int Distance(Square sq1, Square sq2) { return SqDistance[sq1][sq2]; }

// Pseudo-random number generator
static uint64_t Rand64() {

Expand Down
4 changes: 1 addition & 3 deletions src/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ typedef struct Position {

extern bool chess960;

extern uint8_t SqDistance[64][64];

extern const int NonPawn[PIECE_NB];

// Zobrist keys
Expand Down Expand Up @@ -98,10 +96,10 @@ INLINE Color ColorOf(Piece piece) { return piece >> 3;}
INLINE PieceType PieceTypeOf(Piece piece) { return piece & 7; }
INLINE Piece MakePiece(Color color, PieceType pt) { return (color << 3) + pt; }

int Distance(const Square sq1, const Square sq2);
INLINE Square MirrorSquare(const Square sq) { return sq ^ 56; } // Mirrors a square horizontally
INLINE Square RelativeSquare(const Color color, const Square sq) { return color == WHITE ? sq : MirrorSquare(sq); }
INLINE Square BlackRelativeSquare(const Color color, const Square sq) { return color == BLACK ? sq : MirrorSquare(sq); }
INLINE int Distance(const Square sq1, const Square sq2) { return SqDistance[sq1][sq2]; }
INLINE int FileOf(Square square) { return square & 7; }
INLINE int RankOf(Square square) { return square >> 3; }
INLINE int RelativeRank(Color color, int rank) { return color == WHITE ? rank : RANK_8 - rank; }
Expand Down
2 changes: 1 addition & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern const int PhaseValue[TYPE_NB];
#define EgScore(s) ((int16_t)((uint16_t)((unsigned)((s) + 0x8000) >> 16)))

// Calculates the phase from the phase values of the pieces left
static inline int UpdatePhase(int value) {
INLINE int UpdatePhase(int value) {
return (value * MidGame + 12) / 24;
}

Expand Down
2 changes: 1 addition & 1 deletion src/onlinesyzygy/onlinesyzygy.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool onlineSyzygy = false;


// Probes lichess syzygy
bool QueryRoot(Position *pos, Move *move, unsigned *wdl, unsigned *dtz) {
bool QueryRoot(const Position *pos, Move *move, unsigned *wdl, unsigned *dtz) {

puts("info string OnlineSyzygy: Querying lichess for a tablebase move...");

Expand Down
2 changes: 1 addition & 1 deletion src/onlinesyzygy/onlinesyzygy.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
extern bool onlineSyzygy;


bool QueryRoot(Position *pos, unsigned *wdl, unsigned *dtz, Move *move);
bool QueryRoot(const Position *pos, unsigned *wdl, unsigned *dtz, Move *move);
14 changes: 11 additions & 3 deletions src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ CONSTR(1) InitReductions() {
Reductions[1][depth][moves] = 1.35 + log(depth) * log(moves) / 2.75; // quiet
}

// Checks whether a move was already searched in multi-pv mode
static bool AlreadySearchedMultiPV(Thread *thread, Move move) {
for (int i = 0; i < thread->multiPV; ++i)
if (thread->rootMoves[i].move == move)
return true;
return false;
}

// Small positive score with some random variance
static int DrawScore(Position *pos) {
return 8 - (pos->nodes & 0x7);
Expand All @@ -70,7 +78,7 @@ static int Quiescence(Thread *thread, Stack *ss, int alpha, const int beta) {
int bestScore = -INFINITE;

// Check time situation
if (OutOfTime(thread) || LoadRelaxed(ABORT_SIGNAL))
if (OutOfTime(thread) || loadRelaxed(ABORT_SIGNAL))
longjmp(thread->jumpBuffer, true);

// Position is drawn
Expand Down Expand Up @@ -193,7 +201,7 @@ static int AlphaBeta(Thread *thread, Stack *ss, int alpha, int beta, Depth depth
const bool root = ss->ply == 0;

// Check time situation
if (OutOfTime(thread) || LoadRelaxed(ABORT_SIGNAL))
if (OutOfTime(thread) || loadRelaxed(ABORT_SIGNAL))
longjmp(thread->jumpBuffer, true);

// Early exits
Expand Down Expand Up @@ -640,7 +648,7 @@ static void *IterativeDeepening(void *voidThread) {
// Jump here and return if we run out of allocated time mid-search
if (setjmp(thread->jumpBuffer)) break;

// Search position, using aspiration windows for higher depths
// Search the position, once for each multi-pv
for (thread->multiPV = 0; thread->multiPV < multiPV; ++thread->multiPV)
AspirationWindow(thread, ss);

Expand Down
4 changes: 2 additions & 2 deletions src/syzygy.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static bool ProbeWDL(const Position *pos, int *score, int *bound, int ply) {
}

// Probe local Syzygy files using Pyrrhic to get an optimal move
static bool ProbeRoot(Position *pos, Move *move, unsigned *wdl, unsigned *dtz) {
static bool ProbeRoot(const Position *pos, Move *move, unsigned *wdl, unsigned *dtz) {

// Call Pyrrhic
unsigned result = tb_probe_root(
Expand Down Expand Up @@ -96,7 +96,7 @@ static bool ProbeRoot(Position *pos, Move *move, unsigned *wdl, unsigned *dtz) {
}

// Get optimal move from Syzygy tablebases
static bool SyzygyMove(Position *pos) {
static bool SyzygyMove(const Position *pos) {

Move move;
unsigned wdl, dtz;
Expand Down
8 changes: 0 additions & 8 deletions src/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ void InitThreads(int count) {
threads[i].count = count;
}

// Checks whether a move was already searched in multi-pv mode
bool AlreadySearchedMultiPV(Thread *thread, Move move) {
for (int i = 0; i < thread->multiPV; ++i)
if (thread->rootMoves[i].move == move)
return true;
return false;
}

// Sorts all rootmoves searched by multiPV
void SortRootMoves(Thread *thread, int multiPV) {
for (int i = 0; i < multiPV; ++i) {
Expand Down
1 change: 0 additions & 1 deletion src/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ extern Thread *threads;


void InitThreads(int threadCount);
bool AlreadySearchedMultiPV(Thread *thread, Move move);
void SortRootMoves(Thread *thread, int multiPV);
uint64_t TotalNodes();
uint64_t TotalTBHits();
Expand Down
2 changes: 1 addition & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define INLINE static inline __attribute__((always_inline))
#define CONSTR(prio) static __attribute__((constructor (1000 + prio))) void

#define LoadRelaxed(x) atomic_load_explicit(&(x), memory_order_relaxed)
#define loadRelaxed(x) atomic_load_explicit(&(x), memory_order_relaxed)

#define lastMoveNullMove (!root && history(-1).move == NOMOVE)
#define history(offset) (pos->gameHistory[pos->histPly + offset])
Expand Down
9 changes: 4 additions & 5 deletions src/uci.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ static void ParseTimeControl(const char *str, const Position *pos) {
char *searchmoves = strstr(str, "searchmoves ");
if (searchmoves) {
char *move = strtok(searchmoves, " ");
int i = 0;
while ((move = strtok(NULL, " ")))
Limits.searchmoves[i++] = ParseMove(move, pos);
for (int i = 0; (move = strtok(NULL, " ")); ++i)
Limits.searchmoves[i] = ParseMove(move, pos);
}

Limits.timelimit = Limits.time || Limits.movetime;
Expand All @@ -73,11 +72,11 @@ INLINE void Go(Position *pos, char *str) {
// Parses a 'position' and sets up the board
static void Pos(Position *pos, char *str) {

#define IsFen (!strncmp(str, "position fen", 12))
bool isFen = !strncmp(str, "position fen", 12);

// Set up original position. This will either be a
// position given as FEN, or the normal start position
ParseFen(IsFen ? str + 13 : START_FEN, pos);
ParseFen(isFen ? str + 13 : START_FEN, pos);

// Check if there are moves to be made from the initial position
if ((str = strstr(str, "moves")) == NULL) return;
Expand Down

0 comments on commit c000a56

Please sign in to comment.