commit 3c8040f2d15fd247c66f0715591e961cf3dd2ad5
parent 882b3027e9458ad721220d773c5a1081104f8fbf
Author: Luka Kalezic <kaleza98@gmail.com>
Date: Sat, 6 Jan 2024 17:42:39 +0100
Add goto condition at the end
Diffstat:
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/magichex/src/magichex.c b/magichex/src/magichex.c
@@ -170,27 +170,23 @@ bool solve(HexagonEntry hexagon[])
if (occupation[hexagonEntry->lo-o] < number_hex_entries)
return false; /* another variable has the same value */
occupation[hexagonEntry->lo-o] = i; /* occupy hexagonEntry->lo */
- //goto restart;
}
}
- bool k = false;
+ bool update_boundaries = false;
/* now propagate the alldifferent results to the bounds */
for (i=0; i<number_hex_entries; i++) {
HexagonEntry *hexagonEntry = &hexagon[i];
if (hexagonEntry->lo < hexagonEntry->hi) {
if (occupation[hexagonEntry->lo-o] < number_hex_entries) {
hexagonEntry->lo++;
- k = true;
+ update_boundaries = true;
}
if (occupation[hexagonEntry->hi-o] < number_hex_entries) {
hexagonEntry->hi--;
- k = true;
+ update_boundaries = true;
}
}
}
- if(k){
- goto restart;
- }
/* the < constraints; all other corners are smaller than the first
one (eliminate rotational symmetry) */
for (i=1; i<sizeof(corners)/sizeof(corners[0]); i++) {
@@ -212,17 +208,17 @@ bool solve(HexagonEntry hexagon[])
/* line */
f = sum(hexagon+r*i+max(0,i+1-n), min(i+n,r+n-i-1), 1, hexagon, hexagon+number_hex_entries);
if (f==NOSOLUTION) return false;
- if (f==CHANGED) k = true;
+ if (f==CHANGED) update_boundaries = true;
/* column (diagonal down-left in the hexagon) */
f = sum(hexagon+i+max(0,i+1-n)*r, min(i+n,r+n-i-1), r, hexagon, hexagon+number_hex_entries);
if (f==NOSOLUTION) return false;
- if (f==CHANGED) k = true;
+ if (f==CHANGED) update_boundaries = true;
/* diagonal (down-right) */
f = sum(hexagon-n+1+i+max(0,n-i-1)*(r+1), min(i+n,r+n-i-1), r+1, hexagon, hexagon+number_hex_entries);
if (f==NOSOLUTION) return false;
- if (f==CHANGED) k = true;
+ if (f==CHANGED) update_boundaries = true;
}
- if(k){
+ if(update_boundaries){
goto restart;
}
return true; // all done