Skip to content

Commit

Permalink
Experimental -p <ply> option.
Browse files Browse the repository at this point in the history
Positions with dtz <= <ply> are stored with dtz = 1, leaving it up to the engine or probing code to search for a path to mate or a winning capture.
The value of <ply> is at present not stored in the DTZ table, which is a guarantee for confusion. This should be fixed in the future.
  • Loading branch information
Ronald de Man committed Apr 19, 2015
1 parent 5df99c1 commit 2231763
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/reduce.c
Expand Up @@ -237,16 +237,16 @@ void reconstruct_table(ubyte *table, char color, struct dtz_map *map)
v[255] = inv_map[1][0];
if (map->ply_accurate_win)
for (i = 0; i < DRAW_RULE; i++)
v[i + 1] = inv_map[0][i];
v[i + 1] = inv_map[0][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[i + 1] = inv_map[0][i / 2];
v[i + 1] = inv_map[0][i + 1 > dtz_ply ? i / 2 : 0];
if (map->ply_accurate_loss)
for (i = 0; i < DRAW_RULE; i++)
v[254 - i] = inv_map[1][i];
v[254 - i] = inv_map[1][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[254 - i] = inv_map[1][i / 2];
v[254 - i] = inv_map[1][i + 1 > dtz_ply ? i / 2 : 0];
for (; i <= REDUCE_PLY; i += 2) {
v[1 + DRAW_RULE + (i - DRAW_RULE) / 2] = inv_map[2][(i - DRAW_RULE) / 2];
v[254 - DRAW_RULE - (i - DRAW_RULE) / 2] = inv_map[3][(i - DRAW_RULE) / 2];
Expand Down
8 changes: 4 additions & 4 deletions src/reducep.c
Expand Up @@ -240,16 +240,16 @@ void reconstruct_table(ubyte *table, char color, struct dtz_map *map)
v[1] = num;
if (map->ply_accurate_win)
for (i = 0; i < DRAW_RULE; i++)
v[i + 2] = inv_map[0][i];
v[i + 2] = inv_map[0][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[i + 2] = inv_map[0][i / 2];
v[i + 2] = inv_map[0][i + 1 > dtz_ply ? i / 2 : 0];
if (map->ply_accurate_loss)
for (i = 0; i < DRAW_RULE; i++)
v[254 - i] = inv_map[1][i];
v[254 - i] = inv_map[1][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[254 - i] = inv_map[1][i / 2];
v[254 - i] = inv_map[1][i + 1 > dtz_ply ? i / 2 : 0];
for (; i <= REDUCE_PLY; i += 2) {
v[2 + DRAW_RULE + (i - DRAW_RULE) / 2] = inv_map[2][(i - DRAW_RULE) / 2];
v[254 - DRAW_RULE - (i - DRAW_RULE) / 2] = inv_map[3][(i - DRAW_RULE) / 2];
Expand Down
22 changes: 13 additions & 9 deletions src/tbgen.c
Expand Up @@ -117,6 +117,7 @@ static int maxsymbols = 4095;
static int only_generate = 0;
static int generate_dtz = 1;
static int generate_wdl = 1;
static int dtz_ply = 0;

static char *tablename;

Expand Down Expand Up @@ -388,10 +389,10 @@ void sort_values(long64 *stats, struct dtz_map *dtzmap, int side, int pa_w, int
#ifndef SUICIDE
if (dtzmap->ply_accurate_win)
for (i = 0; i < DRAW_RULE; i++)
freq[0][i] += stats[i + 1];
freq[0][i + 1 > dtz_ply ? i : 0] += stats[i + 1];
else
for (i = 0; i < DRAW_RULE; i++)
freq[0][i / 2] += stats[i + 1];
freq[0][i + 1 > dtz_ply ? i / 2 : 0] += stats[i + 1];
#else
if (dtzmap->ply_accurate_win)
for (i = 2; i < DRAW_RULE; i++)
Expand All @@ -406,10 +407,10 @@ void sort_values(long64 *stats, struct dtz_map *dtzmap, int side, int pa_w, int
#ifndef SUICIDE
if (dtzmap->ply_accurate_loss)
for (i = 0; i < DRAW_RULE; i++)
freq[1][i] += stats[1023 - i - 1];
freq[1][i + 1 > dtz_ply ? i : 0] += stats[1023 - i - 1];
else
for (i = 0; i < DRAW_RULE; i++)
freq[1][i / 2] += stats[1023 - i - 1];
freq[1][i + 1 > dtz_ply ? i / 2 : 0] += stats[1023 - i - 1];
#else
if (dtzmap->ply_accurate_loss)
for (i = 1; i < DRAW_RULE; i++)
Expand Down Expand Up @@ -472,16 +473,16 @@ void prepare_dtz_map(ubyte *v, struct dtz_map *map)
v[MATE] = inv_map[1][0];
if (map->ply_accurate_win)
for (i = 0; i < DRAW_RULE; i++)
v[WIN_IN_ONE + i] = inv_map[0][i];
v[WIN_IN_ONE + i] = inv_map[0][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[WIN_IN_ONE + i] = inv_map[0][i / 2];
v[WIN_IN_ONE + i] = inv_map[0][i + 1 > dtz_ply ? i / 2 : 0];
if (map->ply_accurate_loss)
for (i = 0; i < DRAW_RULE; i++)
v[LOSS_IN_ONE - i] = inv_map[1][i];
v[LOSS_IN_ONE - i] = inv_map[1][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[LOSS_IN_ONE - i] = inv_map[1][i / 2];
v[LOSS_IN_ONE - i] = inv_map[1][i + 1 > dtz_ply ? i / 2 : 0];
for (; i <= REDUCE_PLY; i++) {
v[WIN_IN_ONE + i + 1] = inv_map[2][(i - DRAW_RULE) / 2];
v[LOSS_IN_ONE - i] = inv_map[3][(i - DRAW_RULE) / 2];
Expand Down Expand Up @@ -543,7 +544,7 @@ int main(int argc, char **argv)

numthreads = 1;
do {
val = getopt_long(argc, argv, "t:gwzsd", options, &longindex);
val = getopt_long(argc, argv, "t:gwzsdp:", options, &longindex);
switch (val) {
case 't':
numthreads = atoi(optarg);
Expand All @@ -564,6 +565,9 @@ int main(int argc, char **argv)
case 'd':
save_to_disk = 1;
break;
case 'p':
dtz_ply = atoi(optarg);
break;
}
} while (val != EOF);

Expand Down
22 changes: 13 additions & 9 deletions src/tbgenp.c
Expand Up @@ -118,6 +118,7 @@ static int maxsymbols = 4095;
static int only_generate = 0;
static int generate_dtz = 1;
static int generate_wdl = 1;
static int dtz_ply = 0;

static char *tablename;

Expand Down Expand Up @@ -510,19 +511,19 @@ void sort_values(long64 *stats, struct dtz_map *dtzmap, int side, int pa_w, int
freq[0][0] = stats[0];
if (dtzmap->ply_accurate_win)
for (i = 0; i < DRAW_RULE; i++)
freq[0][i] += stats[i + 1];
freq[0][i + 1 > dtz_ply ? i : 0] += stats[i + 1];
else
for (i = 0; i < DRAW_RULE; i++)
freq[0][i / 2] += stats[i + 1];
freq[0][i + 1 > dtz_ply ? i / 2 : 0] += stats[i + 1];
dtzmap->num[0] = sort_list(freq[0], map[0], inv_map[0]);

freq[1][0] = stats[STAT_MATE];
if (dtzmap->ply_accurate_loss)
for (i = 0; i < DRAW_RULE; i++)
freq[1][i] += stats[STAT_MATE - i - 1];
freq[1][i + 1 > dtz_ply ? i : 0] += stats[STAT_MATE - i - 1];
else
for (i = 0; i < DRAW_RULE; i++)
freq[1][i / 2] += stats[STAT_MATE - i - 1];
freq[1][i + 1 > dtz_ply ? i / 2 : 0] += stats[STAT_MATE - i - 1];
dtzmap->num[1] = sort_list(freq[1], map[1], inv_map[1]);

for (i = DRAW_RULE; i < MAX_PLY; i++)
Expand Down Expand Up @@ -575,16 +576,16 @@ void prepare_dtz_map(ubyte *v, struct dtz_map *map)
v[MATE] = inv_map[1][0];
if (map->ply_accurate_win)
for (i = 0; i < DRAW_RULE; i++)
v[WIN_IN_ONE + i] = inv_map[0][i];
v[WIN_IN_ONE + i] = inv_map[0][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[WIN_IN_ONE + i] = inv_map[0][i / 2];
v[WIN_IN_ONE + i] = inv_map[0][i + 1 > dtz_ply ? i / 2 : 0];
if (map->ply_accurate_loss)
for (i = 0; i < DRAW_RULE; i++)
v[LOSS_IN_ONE - i] = inv_map[1][i];
v[LOSS_IN_ONE - i] = inv_map[1][i + 1 > dtz_ply ? i : 0];
else
for (i = 0; i < DRAW_RULE; i++)
v[LOSS_IN_ONE - i] = inv_map[1][i / 2];
v[LOSS_IN_ONE - i] = inv_map[1][i + 1 > dtz_ply ? i / 2 : 0];
for (; i < REDUCE_PLY; i++) {
v[WIN_IN_ONE + i + 2] = inv_map[2][(i - DRAW_RULE) / 2];
v[LOSS_IN_ONE - i] = inv_map[3][(i - DRAW_RULE) / 2];
Expand Down Expand Up @@ -647,7 +648,7 @@ int main(int argc, char **argv)

numthreads = 1;
do {
val = getopt_long(argc, argv, "t:gwzsd", options, &longindex);
val = getopt_long(argc, argv, "t:gwzsdp:", options, &longindex);
switch (val) {
case 't':
numthreads = atoi(optarg);
Expand All @@ -668,6 +669,9 @@ int main(int argc, char **argv)
case 'd':
save_to_disk = 1;
break;
case 'p':
dtz_ply = atoi(optarg);
break;
}
} while (val != EOF);

Expand Down

0 comments on commit 2231763

Please sign in to comment.