
previous

page 10
next
So that deals with the 4 square cases. The 3, 2 and 1 square cases will be very similar.
In fact, if you study hor_clash_check carefully, you'll realise that the only thing that changes is the 6. It will be 5 for the 3 square case, 4 for the 2 square case and 3 for the 1 square case.
In other words, the number of squares plus 2.
function hor_clash_check(r0,c0,n) {
var ok=true;
for (r=r0;r<(r0+3);r++) {
for (c=c0;c<(c0+n+2);c++) {
var a=get_a(r,c);
if (a!=7) {ok=false; break;}
}
if (!ok) break;
}
return ok;
}
var ok=true;
for (r=r0;r<(r0+3);r++) {
for (c=c0;c<(c0+n+2);c++) {
var a=get_a(r,c);
if (a!=7) {ok=false; break;}
}
if (!ok) break;
}
return ok;
}
Make sure that you change hor4() to reflect this change.
Now for a little challenge for you - create ver_clash_check(r0,c0,n).
And after that we'll change hor4() to hor(n) - now that's an even bigger challenge!
previous
next