I have many global pointers (over 100) to unsigned char data that I malloced. Each element is a "distance to win" in plies, just 0 for an immediate loss, 1 for mate in 1, 2 for mated in 2, 3 for mate in 3, etc.
Looks like this
unsigned char *g_tablebase_01;
unsigned char *g_tablebase_02;
unsigned char *g_tablebase_03;
unsigned char *g_tablebase_04;
They are initialized in a routine such as:
g_tablebase_01 = (unsigned char *)malloc(bytes_needed_01);
g_tablebase_02 = (unsigned char *)malloc(bytes_needed_02);
g_tablebase_03 = (unsigned char *)malloc(bytes_needed_03);
where bytes_needed_01, bytes_needed_02, etc are values I can compute depending on the size of the tablebase.
I would like to have just one routine to set the UNKNOWN values to draws at the end. Right now I am doing it the lazy way, with a separate routine for each tablebase
Code: Select all
switch(which_tb)
{
case 1:
for(i = 0; i < how_many_positions; i++)
{
tb_value = g_tablebase_01[i];
if(tb_value == DB_UNKNOWN_THAT_FITS_INTO_8_BITS)
{
g_tablebase_01[i] = TB_DRAW;
}
}
break;
case 2:
for(i = 0; i < how_many_positions; i++)
{
tb_value = g_tablebase_02[i];
if(tb_value == DB_UNKNOWN_THAT_FITS_INTO_8_BITS)
{
g_tablebase_02[i] = TB_DRAW;
}
}
break;
}
Code: Select all
void set_db_unknowns_to_draw(unsigned char **your_pointer, unsigned long total_positions)
{
unsigned long i;
for(i = 0; i < total_positions; i++)
{
db_value = *(your_pointer[i]);
if(db_value == TB_UNKNOWN)
{
*(your_pointer[i]) = TB_DRAW;
}
}
}
Anybody remember how to do this "C 101" thing?
Thanks in advance.