Discussion of chess software programming and technical issues.
Moderators: hgm , Rebel , chrisw
EvgeniyZh
Posts: 43 Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel
Post
by EvgeniyZh » Thu Dec 04, 2014 2:28 am
I'm trying to add Scorpio EGBB support to engine.
Here is code for loading:
Code: Select all
static void load_egbb_library() {
HMODULE hmod;
__PLOAD_EGBB __load_egbb;
const char* main_path = option_get("Bitbase Path");
uint32_t egbb_cache_size = option_get_int("Bitbase Cache Size");
char path[256];
strcpy(path, main_path);
strcat(path, EGBB_NAME);
if (hmod)
FreeLibrary(hmod);
if(hmod = LoadLibrary(path)) {
__load_egbb = (__PLOAD_EGBB) GetProcAddress(hmod,"load_egbb_xmen");
__probe_egbb = (__PROBE_EGBB) GetProcAddress(hmod,"probe_egbb_xmen");
__load_egbb(main_path, egbb_cache_size, egbb_load_type);
egbb_is_loaded = 1;
printf("Bitbase loaded\n");
} else {
//printf( "%d\n",GetLastError());
egbb_is_loaded = 0;
printf("Bitbase not loaded\n");
}
}
for probing:
Code: Select all
if (egbb_is_loaded && (mat_info->flags & MatBitbaseFlag) != 0) {
const sq_t *ptr;
int32_t from;
int32_t score;
for (from=0; from < 64; ++from) {
if (board->square[SQUARE_FROM_64(from)] == Empty) continue;
switch (board->square[SQUARE_FROM_64(from)]) {
case WP: ADD_PIECE(WPawn); break;
case BP: ADD_PIECE(BPawn); break;
case WN: ADD_PIECE(WKnight); break;
case BN: ADD_PIECE(BKnight); break;
case WB: ADD_PIECE(WBishop); break;
case BB: ADD_PIECE(BBishop); break;
case WR: ADD_PIECE(WRook); break;
case BR: ADD_PIECE(BRook); break;
case WQ: ADD_PIECE(WQueen); break;
case BQ: ADD_PIECE(BQueen); break;
case WK: egbb_square[0] = from; break;
case BK: egbb_square[1] = from; break;
default: break;
}
}
++tbhits;
score = __probe_egbb(player, egbb_piece, egbb_square);
if(score != NotFound) {
if (score == 0) {
return ValueDraw;
} else {
return score;
}
}
}
Using version 4.1 x64, everyting is loads OK, but while trying to probe I get segmentation fault in
Code: Select all
score = __probe_egbb(player, egbb_piece, egbb_square);
What could the problem be?
Ferdy
Posts: 4833 Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines
Post
by Ferdy » Thu Dec 04, 2014 3:58 am
Where is the declaration of egbb_piece and egbb_square? Can you also show your ADD_PIECE() routine?
EvgeniyZh
Posts: 43 Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel
Post
by EvgeniyZh » Thu Dec 04, 2014 8:40 am
Ferdy wrote: Where is the declaration of egbb_piece and egbb_square? Can you also show your ADD_PIECE() routine?
of course all variables are declared:
Code: Select all
int32_t total_pieces;
int32_t player;
//int32_t w_ksq;
//int32_t b_ksq;
int32_t egbb_piece[MAX_PIECES];
int32_t egbb_square[MAX_PIECES];
player = board->turn;
total_pieces = 2;
for (int32_t i = 0; i < MAX_PIECES; ++i) {
egbb_piece[i] = 0;
egbb_square[i] = 0;
}
egbb_piece[0] = WKing;
egbb_piece[1] = BKing;
and:
Code: Select all
#define ADD_PIECE(type) {\
egbb_piece[total_pieces] = type;\
egbb_square[total_pieces] = from;\
++total_pieces;\
};
While debugging I checked the parameters and I'm pretty sure they are OK: variable for side and two arrays with type of piece and square it's placed.
Ferdy
Posts: 4833 Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines
Post
by Ferdy » Thu Dec 04, 2014 9:33 am
Which egbb files did you use, be sure you are using the new ones.
Ferdy
Posts: 4833 Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines
Post
by Ferdy » Thu Dec 04, 2014 10:31 am
EvgeniyZh wrote: Ferdy wrote: Where is the declaration of egbb_piece and egbb_square? Can you also show your ADD_PIECE() routine?
of course all variables are declared:
Code: Select all
int32_t total_pieces;
int32_t player;
//int32_t w_ksq;
//int32_t b_ksq;
int32_t egbb_piece[MAX_PIECES];
int32_t egbb_square[MAX_PIECES];
player = board->turn;
total_pieces = 2;
for (int32_t i = 0; i < MAX_PIECES; ++i) {
egbb_piece[i] = 0;
egbb_square[i] = 0;
}
egbb_piece[0] = WKing;
egbb_piece[1] = BKing;
and:
Code: Select all
#define ADD_PIECE(type) {\
egbb_piece[total_pieces] = type;\
egbb_square[total_pieces] = from;\
++total_pieces;\
};
While debugging I checked the parameters and I'm pretty sure they are OK: variable for side and two arrays with type of piece and square it's placed.
Looks fine so far.
EvgeniyZh wrote: of course all variables are declared:
Those are arrays I want to see its size. They are not shown in your first post. What is the value of this MAX_PIECES?
Do you have a chess position where seg-fault is triggered?
Also make sure you follow the board representation of egbb probing.
EvgeniyZh
Posts: 43 Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel
Post
by EvgeniyZh » Thu Dec 04, 2014 11:10 am
Ferdy wrote: Do you have a chess position where seg-fault is triggered?
I'm pretty sure it fails any time it calls the function. For example:
Ferdy wrote: Those are arrays I want to see its size. They are not shown in your first post. What is the value of this MAX_PIECES?
Ferdy wrote: Also make sure you follow the board representation of egbb probing.
Well the variable values are legal(pieces 1,7 for kings, and 3 for piece, square value <64, player is 0 or 1), so even if there is some mistake there shouldn't be segfault.
Ferdy
Posts: 4833 Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines
Post
by Ferdy » Thu Dec 04, 2014 12:36 pm
That is all from me for now.
One more thing, use the latest egbb files. Try the latest 4-men here for example. But use the latest egbbdll.
https://sites.google.com/site/dshawul/home
EvgeniyZh
Posts: 43 Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel
Post
by EvgeniyZh » Thu Dec 04, 2014 1:23 pm
Yeah, I'm using latest ones, exactly from this site.
The exact values are:
egbb_piece == [1,7,3,0....]
egbb_square == [5, 36, 58, 0......]
player == 1
fridokar
Posts: 9 Joined: Thu Dec 04, 2014 2:14 pm
Post
by fridokar » Thu Dec 04, 2014 10:04 pm
For "probe_egbb_xmen" treat the kings like the other pieces. Try:
Code: Select all
case WK: ADD_PIECE(WKing); break;
case BK: ADD_PIECE(BKing); break;
EvgeniyZh
Posts: 43 Joined: Fri Sep 19, 2014 4:54 pm
Location: Israel
Post
by EvgeniyZh » Thu Dec 04, 2014 11:04 pm
fridokar wrote: For "probe_egbb_xmen" treat the kings like the other pieces. Try:
Code: Select all
case WK: ADD_PIECE(WKing); break;
case BK: ADD_PIECE(BKing); break;
That's worked! Thanks a lot!