i working on first black jack game , keep getting confused simplest thing. problem in if statement :
if ( cardsinhand < 7 && newcard != firstcard && newcard != secondcard )
and when press hit me button deal me same card on , on again. here function. need info in if statement true , execute, otherwise not execute.
cardsinhand = 2 firstcard = math.floor(math.random() * 1000 % 52) secondcard = math.floor(math.random() * 1000 % 52) newcard = math.floor(math.random() * 1000 % 52) function hitcard() { if ( cardsinhand < 7 && newcard != firstcard && newcard != secondcard ) { document.images[cardsinhand].src = "http://www.biogow/images/cards/gbcard" + newcard + ".gif" cardsinhand++ } }
any idea why isnt working right?
it's not problem if
statement itself. appears this:
newcard = math.floor(math.random() * 1000 % 52)
is being done once rather every time hit. means will same card on , over.
you should recalculate new card every time perform hit operation.
you should how you're generating cards. normally, use deck (containing 1 or more "real" decks) probabilities change cards removed, in real life.
that fix skewing problem using * 1000 % 52
tend prefer cards @ 1 end of "deck".
Comments
Post a Comment