previous

page 7

next
checking for acceptable clicks

What constitutes an acceptable first click? click me for my answer

What constitutes an acceptable sequence? click me for my answer

What constitutes an acceptable second click? click me for my answer

The above suggests that it may be useful to have the following simple functions. I've decided to store these low level functions in a separate file which I've named helpers.js.

function check_sequence(arr) { // eg [10,35,8,33]
var ok=true;
var val0=value(arr[0]);
var col0=colour(arr[0]);
for (var i=1;i<arr.length;i++) {
var val1=value(arr[i]);
var col1=colour(arr[i]);
if (val1!=val0-1) ok=false;
if (col0==col1) ok=false;
val0=val1; col0=col1;
}
return ok;
}
function colour(n) {
if (n<26) return 'black'; else return 'red';
}
// Is card the last card in its column?
function last(card) {
var ok=false;
var c=card.style.gridColumnStart; // column #
var r=card.style.gridRowStart; // row #
if (g_main_cols[c].length==r) ok=true;
if (g_main_cols[c].length==0) ok=true;
return ok;
}
function value(n) { // returns 1, 2, ... 13
return n%13+1;
}
previous
next