From 74a81f7a254e7bdb27b959cc4e4b0f87f0da58f1 Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Sun, 1 Oct 2023 22:11:26 -0400 Subject: [PATCH 01/10] There's no reason to loop over the slack files. --- conditions/wormhole.c | 14 +++++---- output/plaintext/condition.c | 61 ++++++++++++++++++++---------------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/conditions/wormhole.c b/conditions/wormhole.c index 5f103cfb8c..fae6bcf802 100644 --- a/conditions/wormhole.c +++ b/conditions/wormhole.c @@ -307,12 +307,14 @@ void wormhole_initialse_solving(slice_index si) { square s; - for (s = square_a1; s<=square_h8; ++s) - if (TSTFLAG(sq_spec(s),Wormhole)) - { - wormhole_positions[nr_wormholes] = s; - ++nr_wormholes; - } + int j; + for (s = square_a1; s<=square_a8; s += (square_a2 - square_a1)) + for (j = 0; j Date: Tue, 3 Oct 2023 22:34:46 -0400 Subject: [PATCH 02/10] Making the code a bit more generic. --- conditions/wormhole.c | 7 ++++-- output/plaintext/condition.c | 42 +++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/conditions/wormhole.c b/conditions/wormhole.c index fae6bcf802..12f57ed94d 100644 --- a/conditions/wormhole.c +++ b/conditions/wormhole.c @@ -310,11 +310,14 @@ void wormhole_initialse_solving(slice_index si) int j; for (s = square_a1; s<=square_a8; s += (square_a2 - square_a1)) for (j = 0; j Date: Wed, 4 Oct 2023 07:54:20 -0400 Subject: [PATCH 03/10] I like this version better. --- conditions/wormhole.c | 15 ++------ output/plaintext/condition.c | 72 ++++++++++++------------------------ 2 files changed, 28 insertions(+), 59 deletions(-) diff --git a/conditions/wormhole.c b/conditions/wormhole.c index 12f57ed94d..74865a9d56 100644 --- a/conditions/wormhole.c +++ b/conditions/wormhole.c @@ -306,18 +306,11 @@ void wormhole_initialse_solving(slice_index si) nr_wormholes = 0; { - square s; - int j; + square s, j; for (s = square_a1; s<=square_a8; s += (square_a2 - square_a1)) - for (j = 0; j Date: Wed, 4 Oct 2023 19:16:45 -0400 Subject: [PATCH 04/10] Adding slack rows above and below. --- position/board.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/position/board.h b/position/board.h index 361822cc07..8cf33d9f67 100644 --- a/position/board.h +++ b/position/board.h @@ -225,8 +225,8 @@ enum max_castling = queenside_castling }; -extern SquareFlags zzzan[square_h8 - square_a1 + 1]; -#define sq_spec(n) (zzzan[(n) - square_a1]) +extern SquareFlags zzzan[(one_row + 1) + (square_h8 - square_a1 + 1) + (one_row + 1)]; // for this array we need slack rows above and below +#define sq_spec(n) (zzzan[(n) - (square_a1 - one_row - 1)]) extern int zzzao[square_h8 - square_a1 + 1]; #define sq_num(n) (zzzao[(n) - square_a1]) From c3b377d9259015eaf0036797df96bcd71cacbe9a Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Wed, 4 Oct 2023 20:16:25 -0400 Subject: [PATCH 05/10] Setting the array dimension properly everywhere. --- position/board.c | 2 +- position/board.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/position/board.c b/position/board.c index 194cc1f7ee..faa30298ca 100644 --- a/position/board.c +++ b/position/board.c @@ -80,7 +80,7 @@ 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[(one_row + 1) + (square_h8 - square_a1 + 1) + (one_row + 1)]; int zzzao[square_h8 - square_a1 + 1]; diff --git a/position/board.h b/position/board.h index 8cf33d9f67..cd10633bd6 100644 --- a/position/board.h +++ b/position/board.h @@ -226,7 +226,7 @@ enum }; extern SquareFlags zzzan[(one_row + 1) + (square_h8 - square_a1 + 1) + (one_row + 1)]; // for this array we need slack rows above and below -#define sq_spec(n) (zzzan[(n) - (square_a1 - one_row - 1)]) +#define sq_spec(n) (zzzan[(n) - (square_a1 - (one_row + 1))]) extern int zzzao[square_h8 - square_a1 + 1]; #define sq_num(n) (zzzao[(n) - square_a1]) From 26a848a158c70a4afc2b71daeafee9827c549650 Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Wed, 4 Oct 2023 20:26:13 -0400 Subject: [PATCH 06/10] Using the right identifier. --- position/board.c | 2 +- position/board.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/position/board.c b/position/board.c index faa30298ca..15debd248a 100644 --- a/position/board.c +++ b/position/board.c @@ -80,7 +80,7 @@ square const boardnum[65] = { /* eighth rank */ 368, 369, 370, 371, 372, 373, 374, square_h8, /* end marker */ 0}; -SquareFlags zzzan[(one_row + 1) + (square_h8 - square_a1 + 1) + (one_row + 1)]; +SquareFlags zzzan[(onerow + 1) + (square_h8 - square_a1 + 1) + (onerow + 1)]; int zzzao[square_h8 - square_a1 + 1]; diff --git a/position/board.h b/position/board.h index cd10633bd6..4a3d0a7f9e 100644 --- a/position/board.h +++ b/position/board.h @@ -225,8 +225,8 @@ enum max_castling = queenside_castling }; -extern SquareFlags zzzan[(one_row + 1) + (square_h8 - square_a1 + 1) + (one_row + 1)]; // for this array we need slack rows above and below -#define sq_spec(n) (zzzan[(n) - (square_a1 - (one_row + 1))]) +extern SquareFlags zzzan[(onerow + 1) + (square_h8 - square_a1 + 1) + (onerow + 1)]; // for this array we need slack rows above and below +#define sq_spec(n) (zzzan[(n) - (square_a1 - (onerow + 1))]) extern int zzzao[square_h8 - square_a1 + 1]; #define sq_num(n) (zzzao[(n) - square_a1]) From e03fb4e5397508a714396f5df086b0bf0ece5a9d Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Thu, 5 Oct 2023 06:43:21 -0400 Subject: [PATCH 07/10] Tightening a comment. --- position/board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/position/board.h b/position/board.h index 4a3d0a7f9e..d6f611a092 100644 --- a/position/board.h +++ b/position/board.h @@ -225,7 +225,7 @@ enum max_castling = queenside_castling }; -extern SquareFlags zzzan[(onerow + 1) + (square_h8 - square_a1 + 1) + (onerow + 1)]; // for this array we need slack rows above and below +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[(n) - (square_a1 - (onerow + 1))]) extern int zzzao[square_h8 - square_a1 + 1]; From 2dad357426b73753463a37d176e54e94c9b07a45 Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Fri, 6 Oct 2023 22:35:54 -0400 Subject: [PATCH 08/10] Switching to the old comment style. --- position/board.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/position/board.h b/position/board.h index d6f611a092..57e78cb634 100644 --- a/position/board.h +++ b/position/board.h @@ -225,7 +225,7 @@ enum max_castling = queenside_castling }; -extern SquareFlags zzzan[(onerow + 1) + (square_h8 - square_a1 + 1) + (onerow + 1)]; // for this array we need slack entries all around the board +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[(n) - (square_a1 - (onerow + 1))]) extern int zzzao[square_h8 - square_a1 + 1]; From b98ef35e8c5f16ff8488780f38bab10f90b38aa7 Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Mon, 9 Oct 2023 13:37:59 -0400 Subject: [PATCH 09/10] Capturing our assumptions in asserts. --- position/board.c | 13 +++++++++++++ position/board.h | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/position/board.c b/position/board.c index 15debd248a..dc65acbc54 100644 --- a/position/board.c +++ b/position/board.c @@ -84,6 +84,19 @@ 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 diff --git a/position/board.h b/position/board.h index 57e78cb634..f5eaac834b 100644 --- a/position/board.h +++ b/position/board.h @@ -226,10 +226,11 @@ enum }; 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[(n) - (square_a1 - (onerow + 1))]) +#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) From eb57e1ce2272249fad9810a6715e72db16514898 Mon Sep 17 00:00:00 2001 From: Joshua Green Date: Fri, 20 Oct 2023 07:59:21 -0400 Subject: [PATCH 10/10] Eliminating a shadow. --- output/plaintext/condition.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/output/plaintext/condition.c b/output/plaintext/condition.c index 0c34ced235..81cfe4d4b9 100644 --- a/output/plaintext/condition.c +++ b/output/plaintext/condition.c @@ -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 + max_nr_hunter_walks)) {