previous

page 33

next
the auto facility

You will have noticed while playing the game that eventually you get to the stage when no more manoeuvring is necessary and it's just a matter of moving the cards one at a time to the final panel. This is a rather boring activity!
So our last mission will be for our app to recognise this state and then to automatically complete the game.

So the first question is: how can we tell when the game has reached that stage?

click me for the answer

Have a go at writing auto_check().

function auto_check() {
var ok=true;
for (var c=1;c<9;c++) {
var ids=g_main_cols[c];
if (ids.length>1) {
var v0=value(ids[0]);
for (var j=1;j<ids.length;j++) {
var v1=value(ids[j]);
if (v1>v0) {
ok=false; break;
} else {
v0=v1;
}
}
if (!ok) break;
}
}
return ok;
}
previous
next