previous

page 34

next
the auto facility - testing

Let's indicate when this state is reached by changing the background colour of the main panel to brown.

function move(card1,card2) {
...
save_state();
if (auto_check()) {
var el=document.getElementById('main_panel');
el.style.backgroundColor='brown';
}
}

And here's a clever way to test our new function with just a couple of clicks.

function deal() {
...
// Shuffle(cards);
cards.reverse();
...
}

Now we turn our attention to implementing the auto function. This is not a trivial exercise because if we just get the computer to now move the cards, this will happen so fast that it will appear instantaneous to the player and suddenly there'll be nothing on the screen but the four kings on a brown background.

So my plan is to first find the cards and push them onto a new global array, g_auto_ids. I'm going to create a function auto() to do this.

It will need this new helper function:

function last_card(arr) {
var l=arr.length;
if (l==0) return -1;
return (arr[l-1]);
}
previous
next