Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework search stack #96

Merged
merged 4 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,10 @@ struct S_Board {
int checks = -1;
};

typedef struct Stack {
struct PvTable {
int pvLength[MAXDEPTH + 1];
int pvArray[MAXDEPTH + 1][MAXDEPTH + 1];
int searchHistory[12][Board_sq_num] = { 0 };
int searchKillers[2][MAXDEPTH] = { NOMOVE };
int excludedMoves[MAXDEPTH] = { NOMOVE };
int CounterMoves[Board_sq_num][Board_sq_num] = { 0 };
int eval[MAXDEPTH] = { 0 };
int move[MAXDEPTH] = { 0 };
} S_Stack;
};

extern Bitboard SQUARES_BETWEEN_BB[Board_sq_num][Board_sq_num];
//Hold the data from the uci input to set search parameters and some search data to populate the uci output
Expand Down
9 changes: 4 additions & 5 deletions src/History.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "Board.h"
#include "move.h"
#include "History.h"


//Update the history heuristics of all the quiet moves passed to the function
void updateHH(const S_Board* pos, S_Stack* ss, const int depth, const int bestmove, const S_MOVELIST* quiet_moves) {
void updateHH(const S_Board* pos, Search_data* ss, const int depth, const int bestmove, const S_MOVELIST* quiet_moves) {
//define the history bonus
int bonus = depth * depth;
//Loop through all the quiet moves
Expand All @@ -25,11 +24,11 @@ void updateHH(const S_Board* pos, S_Stack* ss, const int depth, const int bestmo
}

//Returns the history score of a move
int getHHScore(const S_Board* pos, const S_Stack* ss, const int move) {
int getHHScore(const S_Board* pos, const Search_data* ss, const int move) {
return ss->searchHistory[pos->pieces[From(move)]][To(move)];
}
//Resets the history table
void cleanHistory(S_Stack* ss) {
void cleanHistory(Search_data* ss) {
//For every piece [12] moved to every square [64] we reset the searchHistory value
for (int index = 0; index < 12; ++index) {
for (int index2 = 0; index2 < 64; ++index2) {
Expand Down
13 changes: 6 additions & 7 deletions src/History.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "Board.h"
#include "move.h"
#pragma once
#include "Board.h"
#include "move.h"
#include "History.h"
#include <stdio.h>
#include <stdlib.h>
#include "Board.h"
#include "move.h"
#include "search.h"


//Update the history heuristics of all the quiet moves passed to the function
void updateHH(const S_Board* pos, S_Stack* ss, const int depth, const int bestmove, const S_MOVELIST* quiet_moves);
void updateHH(const S_Board* pos, Search_data* ss, const int depth, const int bestmove, const S_MOVELIST* quiet_moves);

//Returns the history score of a move
int getHHScore(const S_Board* pos, const S_Stack* ss, const int move);
int getHHScore(const S_Board* pos, const Search_data* ss, const int move);
2 changes: 1 addition & 1 deletion src/datagen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void make_random_move(S_Board* pos) {


/*
void datagen(S_Board* pos, S_Stack* ss, S_SearchINFO* info)
void datagen(S_Board* pos, Search_data* ss, S_SearchINFO* info)
{
srand(time(NULL));
// Play 5 random moves
Expand Down
14 changes: 11 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ void init_all() {
nnue.init("nn.net");
}

void init_new_game(S_Board* pos, S_Stack* ss, S_SearchINFO* info) {
void init_new_game(S_ThreadData* td) {

//Extract data structures from ThreadData
S_Board* pos = &td->pos;
Search_data* ss = &td->ss;
S_SearchINFO* info = &td->info;
PvTable* pv_table = &td->pv_table;

//For every piece [12] moved to every square [64] we reset the searchHistory value
for (int index = 0; index < 12; ++index) {
for (int index2 = 0; index2 < 64; ++index2) {
Expand All @@ -263,9 +270,9 @@ void init_new_game(S_Board* pos, S_Stack* ss, S_SearchINFO* info) {

//Clean the Pv array
for (int index = 0; index < MAXDEPTH + 1; ++index) {
ss->pvLength[index] = 0;
pv_table->pvLength[index] = 0;
for (int index2 = 0; index2 < MAXDEPTH + 1; ++index2) {
ss->pvArray[index][index2] = NOMOVE;
pv_table->pvArray[index][index2] = NOMOVE;
}
}

Expand Down Expand Up @@ -297,5 +304,6 @@ void init_new_game(S_Board* pos, S_Stack* ss, S_SearchINFO* info) {

// call parse position function
parse_position("position startpos", pos);
return;

}
3 changes: 2 additions & 1 deletion src/init.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once
#include "Board.h"
#include "search.h"

extern Bitboard PieceKeys[12][64];
extern Bitboard enpassant_keys[64];
extern Bitboard SideKey;
extern Bitboard CastleKeys[16];

void init_new_game(S_Board* pos, S_Stack* ss, S_SearchINFO* info);
void init_new_game(S_ThreadData* td);

void init_leapers_attacks();

Expand Down
4 changes: 2 additions & 2 deletions src/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void PrintUciOutput(const int score, const int depth, const S_ThreadData* td, co
" nps " << nps << " time " << GetTimeMs() - td->info.starttime << " pv ";

// loop over the moves within a PV line
for (int count = 0; count < td->ss.pvLength[0]; count++) {
for (int count = 0; count < td->pv_table.pvLength[0]; count++) {
// print PV move
print_move(td->ss.pvArray[0][count]);
print_move(td->pv_table.pvArray[0][count]);
printf(" ");
}

Expand Down
Loading