HTML and CSS Reference
In-Depth Information
sum is less than 17. If it is, it returns true , which tells the calling function to request a new card. If the
value exceeds 17, it returns false .
function more_to_house(){
var ac = 0;
var i;
var sumup = 0;
for (i=0;i<hi;i++) {
sumup += househand[i].value;
if (househand[i].value==1) {ac++;}
}
if (ac>0) {
if ((sumup+10)<=21) {
sumup += 10;
}
}
housetotal = sumup;
if (sumup<17) {
return true;
}
else {
return false;
}
}
If you want to experiment with a different strategy for the house, more_to_house is the function you
change.
Starting a new game can be a challenge for programmers. First of all, it is necessary to understand what
starting again means. For this implementation of blackjack, I provide an option to the player for starting a
new hand, which means continuing with the same deck. To start with a fresh deck that has no cards dealt
out, the player must reload the document. My name for the function that is invoked when the player
presses the n key is newgame . The required actions are to clear the canvas and reset the pointers for
players and dealers hands, as well as the variables holding the horizontal position for the next card. This
function closes with a call to dealstart .
function newgame() {
ctx.clearRect(0,0,cwidth,cheight);
pi=0;
hi=0;
playerxp = 100;
housexp= 500;
dealstart();
}
Shuffling the deck
The technique for shuffling featured in the concentration game (see Chapter 5) represented an
implementation of what my children and I did when playing the game: we spread out the cards and seized
pairs and switched their places. For blackjack, a friend pointed me to a website by Eli Bendersky
( http://eli.thegreenplace.net/2010/05/28/the-intuition-behind-fisher-yates-
 
Search WWH ::




Custom Search