Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

confused over something simple

mrprchrmrprchr Posts: 6Member
I got bored so I decided to make a blackjack game... it turned out to be more frustrating than anything else... I want to determine what card gets put down where...

Randomize
Do
intPlayer2 = Int((52 * Rnd) + 1)
Loop Until (intPlayer2 <> intPlayer1 Or intDealer2 Or intDealer1)

unfortunately what is happening is I get one of the dealers cards that appears both in his hand and my own. I dont want this, so i figured id put the code above in and try to see if I could fix it by preventing the random number from being drawn twice. It still occurs. Could anyone tell me whats wrong (i dont know if maybe i didnt put the parenthesis in the right place or what) the rest of the code seems to be fine and the dealers first two cards are never the same (i ran it about 100 times to check).

Comments

  • DrMartenDrMarten Posts: 748Member
    : I got bored so I decided to make a blackjack game... it turned out to be more frustrating than anything else... I want to determine what card gets put down where...
    :
    : Randomize
    : Do
    : intPlayer2 = Int((52 * Rnd) + 1)
    : Loop Until (intPlayer2 <> intPlayer1 Or intDealer2 Or intDealer1)
    :
    : unfortunately what is happening is I get one of the dealers cards that appears both in his hand and my own. I dont want this, so i figured id put the code above in and try to see if I could fix it by preventing the random number from being drawn twice. It still occurs. Could anyone tell me whats wrong (i dont know if maybe i didnt put the parenthesis in the right place or what) the rest of the code seems to be fine and the dealers first two cards are never the same (i ran it about 100 times to check).
    :



    Try altering your last line to read like this>>

    Loop Until (intPlayer2 <> (intPlayer1 Or intDealer2 Or intDealer1))


    That way all of the conditions are tested.

    Though it might be better like>>

    Loop Until (intPlayer2 <> intPlayer1 Or intPlayer2<>intDealer2 Or intPlayer2<>intDealer1)

    Alternatively chack for which of the 52 cards are drawn each time using an array of 1's and o's for example>>

    In standard basic>>

    Dim Card(52)

    Rem Fill the array with noughts.
    For a=1 to 52
    Card(a)=0
    Next a

    Rem In the next FOR-NEXT loop the array Card(52) will be filled with 1's for the number of cards you wish to draw. Don't forget to set the array to o's for the next deal.

    For Deal=1 to NumberOfCards

    Repeat
    R=(Rnd(1)*52)+1
    Until Card(R)<>1
    Card(R)=1

    Next Deal

    I hope this helps. :-)

  • mrprchrmrprchr Posts: 6Member
    : Try altering your last line to read like this>>
    :
    : Loop Until (intPlayer2 <> (intPlayer1 Or intDealer2 Or intDealer1))
    :
    :
    : That way all of the conditions are tested.
    :
    : Though it might be better like>>
    :
    : Loop Until (intPlayer2 <> intPlayer1 Or intPlayer2<>intDealer2 Or intPlayer2<>intDealer1)
    :
    : Alternatively chack for which of the 52 cards are drawn each time using an array of 1's and o's for example>>
    :
    : In standard basic>>
    :
    : Dim Card(52)
    :
    : Rem Fill the array with noughts.
    : For a=1 to 52
    : Card(a)=0
    : Next a
    :
    : Rem In the next FOR-NEXT loop the array Card(52) will be filled with 1's for the number of cards you wish to draw. Don't forget to set the array to o's for the next deal.
    :
    : For Deal=1 to NumberOfCards
    :
    : Repeat
    : R=(Rnd(1)*52)+1
    : Until Card(R)<>1
    : Card(R)=1
    :
    : Next Deal
    :
    : I hope this helps. :-)
    :

    Surprisingly it didnt do anything different. I zipped the form and all requirements and posted it on ewilkins.travisbsd.org (personal site). Ive checked everything there but cant seem to figure out what it is... maybe i overlooked something? (I did not try your array suggestion, because Ive never used arrays before and its already frustrating me enough :p) I usually can figure most things out on my own but this time im having no luck at all. The code is really a mess.

Sign In or Register to comment.