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

Feature/fix zzz accesses #426

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
12 changes: 5 additions & 7 deletions conditions/wormhole.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,11 @@ void wormhole_initialse_solving(slice_index si)
nr_wormholes = 0;

{
square s;
for (s = square_a1; s<=square_h8; ++s)
if (TSTFLAG(sq_spec(s),Wormhole))
{
wormhole_positions[nr_wormholes] = s;
++nr_wormholes;
}
square s, j;
for (s = square_a1; s<=square_a8; s += (square_a2 - square_a1))
for (j = (square_a1 - square_a1); j<=(square_h1 - square_a1); j += (square_b1 - square_a1))
if (TSTFLAG(sq_spec(s + j),Wormhole))
wormhole_positions[nr_wormholes++] = s + j;
}

{
Expand Down
65 changes: 33 additions & 32 deletions output/plaintext/condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@

static unsigned int WriteWalks(char *pos, piece_walk_type const walks[], unsigned int nr_walks)
{
unsigned int i;
unsigned int walk_index;
unsigned int result = 0;

for (i = 0; i!=nr_walks; ++i)
for (walk_index = 0; walk_index!=nr_walks; ++walk_index)
{
piece_walk_type const walk = walks[i];
piece_walk_type const walk = walks[walk_index];

if (walk<Hunter0 || walk>= (Hunter0 + max_nr_hunter_walks))
{
Expand Down Expand Up @@ -646,54 +646,54 @@ void WriteConditions(FILE *file, condition_writer_type WriteCondition)

case magicsquare:
{
square i;
square i, j;
if (magic_square_type==ConditionType2)
written += append_to_CondLine(&CondLine,written, " %s", ConditionNumberedVariantTypeTab[ConditionType2]);

for (i= square_a1; i <= square_h8; i++) {
if (TSTFLAG(sq_spec(i), MagicSq))
written += append_to_CondLine_square(&CondLine,written,i);
}
for (i= square_a1; i<=square_a8; i+= (square_a2-square_a1))
for (j= (square_a1-square_a1); j<=(square_h1-square_a1); j+= (square_b1-square_a1))
if (TSTFLAG(sq_spec(i+j), MagicSq))
written += append_to_CondLine_square(&CondLine,written,i+j);
break;
}

case whforsqu:
case whconforsqu:
{
square i;
for (i= square_a1; i <= square_h8; i++) {
if (TSTFLAG(sq_spec(i), WhForcedSq))
written += append_to_CondLine_square(&CondLine,written,i);
}
square i, j;
for (i= square_a1; i<=square_a8; i+= (square_a2-square_a1))
for (j= (square_a1-square_a1); j<=(square_h1-square_a1); j+= (square_b1-square_a1))
if (TSTFLAG(sq_spec(i+j), WhForcedSq))
written += append_to_CondLine_square(&CondLine,written,i+j);
break;
}
case blforsqu:
case blconforsqu:
{
square i;
for (i= square_a1; i <= square_h8; i++) {
if (TSTFLAG(sq_spec(i), BlForcedSq))
written += append_to_CondLine_square(&CondLine,written,i);
}
square i, j;
for (i= square_a1; i<=square_a8; i+= (square_a2-square_a1))
for (j= (square_a1-square_a1); j<=(square_h1-square_a1); j+= (square_b1-square_a1))
if (TSTFLAG(sq_spec(i+j), BlForcedSq))
written += append_to_CondLine_square(&CondLine,written,i+j);
break;
}

case whprom_sq:
{
square i;
for (i= square_a1; i <= square_h8; i++) {
if (TSTFLAG(sq_spec(i), WhPromSq))
written += append_to_CondLine_square(&CondLine,written,i);
}
square i, j;
for (i= square_a1; i<=square_a8; i+= (square_a2-square_a1))
for (j= (square_a1-square_a1); j<=(square_h1-square_a1); j+= (square_b1-square_a1))
if (TSTFLAG(sq_spec(i+j), WhPromSq))
written += append_to_CondLine_square(&CondLine,written,i+j);
break;
}
case blprom_sq:
{
square i;
for (i= square_a1; i <= square_h8; i++) {
if (TSTFLAG(sq_spec(i), BlPromSq))
written += append_to_CondLine_square(&CondLine,written,i);
}
square i, j;
for (i= square_a1; i<=square_a8; i+= (square_a2-square_a1))
for (j= (square_a1-square_a1); j<=(square_h1-square_a1); j+= (square_b1-square_a1))
if (TSTFLAG(sq_spec(i+j), BlPromSq))
written += append_to_CondLine_square(&CondLine,written,i+j);
break;
}

Expand All @@ -706,10 +706,11 @@ void WriteConditions(FILE *file, condition_writer_type WriteCondition)

case wormholes:
{
square i;
for (i = square_a1; i<=square_h8; ++i)
if (TSTFLAG(sq_spec(i),Wormhole))
written += append_to_CondLine_square(&CondLine,written,i);
square i, j;
for (i= square_a1; i<=square_a8; i+= (square_a2-square_a1))
for (j= (square_a1-square_a1); j<=(square_h1-square_a1); j+= (square_b1-square_a1))
if (TSTFLAG(sq_spec(i+j),Wormhole))
written += append_to_CondLine_square(&CondLine,written,i+j);
break;
}

Expand Down
15 changes: 14 additions & 1 deletion position/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,23 @@ square const boardnum[65] = {
/* eighth rank */ 368, 369, 370, 371, 372, 373, 374, square_h8,
/* end marker */ 0};

SquareFlags zzzan[square_h8 - square_a1 + 1];
SquareFlags zzzan[(onerow + 1) + (square_h8 - square_a1 + 1) + (onerow + 1)];

int zzzao[square_h8 - square_a1 + 1];

int get_zzzan_index(square const s)
{
#ifndef NDEBUG
int col;
assert((s >= (square_a1 - 1 - onerow)) &&
(s <= (square_h8 + 1 + onerow)));
col = (s % onerow);
assert((col >= (left_file - 1)) &&
(col <= (right_file + 1)));
#endif
return (s - (square_a1 - (onerow + 1)));
}

/* Calculate a square transformation
* @param sq square to be reflected
* @param transformation transformation to be performed
Expand Down
7 changes: 4 additions & 3 deletions position/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,12 @@ enum
max_castling = queenside_castling
};

extern SquareFlags zzzan[square_h8 - square_a1 + 1];
#define sq_spec(n) (zzzan[(n) - square_a1])
extern SquareFlags zzzan[(onerow + 1) + (square_h8 - square_a1 + 1) + (onerow + 1)]; /* for this array we need slack entries all around the board */
#define sq_spec(n) zzzan[get_zzzan_index(n)]
int get_zzzan_index(square s);

extern int zzzao[square_h8 - square_a1 + 1];
#define sq_num(n) (zzzao[(n) - square_a1])
#define sq_num(n) zzzao[(n) - square_a1]

#define NoEdge(i) TSTFLAG(sq_spec(i), NoEdgeSq)
#define SquareCol(i) TSTFLAG(sq_spec(i), SqColor)
Expand Down