Skip to content

Commit

Permalink
Implement TB format extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
syzygy1 committed Apr 25, 2018
1 parent 3442c67 commit c87d365
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
29 changes: 22 additions & 7 deletions src/tbcore.c
Expand Up @@ -1381,12 +1381,19 @@ static int init_table_dtz(struct TBEntry *entry)

ptr->map = data;
if (ptr->flags & 2) {
for (int i = 0; i < 4; i++) {
ptr->map_idx[i] = data + 1 - ptr->map;
data += 1 + data[0];
if (!(ptr->flags & 16)) {
for (int i = 0; i < 4; i++) {
ptr->map_idx[i] = data + 1 - ptr->map;
data += 1 + data[0];
}
} else {
for (int i = 0; i < 4; i++) {
ptr->map_idx[i] = (uint16_t *)data + 1 - (uint16_t *)ptr->map;
data += 2 + 2 * read_le_u16(data);
}
}
data += (uintptr_t)data & 0x01;
}
data += (uintptr_t)data & 0x01;

ptr->precomp->indextable = data;
data += size[0];
Expand Down Expand Up @@ -1414,9 +1421,17 @@ static int init_table_dtz(struct TBEntry *entry)
ptr->map = data;
for (f = 0; f < files; f++) {
if (ptr->flags[f] & 2) {
for (int i = 0; i < 4; i++) {
ptr->map_idx[f][i] = data + 1 - ptr->map;
data += 1 + data[0];
if (!(ptr->flags[f] & 16)) {
for (int i = 0; i < 4; i++) {
ptr->map_idx[f][i] = data + 1 - ptr->map;
data += 1 + data[0];
}
} else {
data += (uintptr_t)data & 0x01;
for (int i = 0; i < 4; i++) {
ptr->map_idx[f][i] = (uint16_t *)data + 1 - (uint16_t *)ptr->map;
data += 2 + 2 * read_le_u16(data);
}
}
}
}
Expand Down
22 changes: 16 additions & 6 deletions src/tbprobe.c
Expand Up @@ -371,10 +371,15 @@ static int probe_dtz_table(Pos *pos, int wdl, int *success)
} while (bb);
}
idx = encode_piece((struct TBEntry_piece *)entry, entry->norm, p, entry->factor);
res = *decompress_pairs(entry->precomp, idx);
uint8_t *w = decompress_pairs(entry->precomp, idx);
res = ((w[1] & 0x0f) << 8) | w[0];

if (entry->flags & 2)
res = entry->map[entry->map_idx[wdl_to_map[wdl + 2]] + res];
if (entry->flags & 2) {
if (!(entry->flags & 16))
res = entry->map[entry->map_idx[wdl_to_map[wdl + 2]] + res];
else
res = ((uint16_t *)entry->map)[entry->map_idx[wdl_to_map[wdl + 2]] + res];
}

if (!(entry->flags & pa_flags[wdl + 2]) || (wdl & 1))
res *= 2;
Expand All @@ -400,10 +405,15 @@ static int probe_dtz_table(Pos *pos, int wdl, int *success)
} while (bb);
}
idx = encode_pawn((struct TBEntry_pawn *)entry, entry->file[f].norm, p, entry->file[f].factor);
res = *decompress_pairs(entry->file[f].precomp, idx);
uint8_t *w = decompress_pairs(entry->file[f].precomp, idx);
res = ((w[1] & 0x0f) << 8) | w[0];

if (entry->flags[f] & 2)
res = entry->map[entry->map_idx[f][wdl_to_map[wdl + 2]] + res];
if (entry->flags[f] & 2) {
if (!(entry->flags[f] & 16))
res = entry->map[entry->map_idx[f][wdl_to_map[wdl + 2]] + res];
else
res = ((uint16_t *)entry->map)[entry->map_idx[f][wdl_to_map[wdl + 2]] + res];
}

if (!(entry->flags[f] & pa_flags[wdl + 2]) || (wdl & 1))
res *= 2;
Expand Down

0 comments on commit c87d365

Please sign in to comment.