jimmyjmmy Posted June 17, 2007 Posted June 17, 2007 Hi, I want to write a script to play baccarat. A pack of cards consists of 52 cards. How do I shuffle this pack of cards. Thanks
Siao Posted June 17, 2007 Posted June 17, 2007 Something like this maybe? #include <Array.au3> $size = 52 $shuffles = 1000 ;create array Dim $aPack[$size+1] = [$size] For $i = 1 to 52 $aPack[$i] = $i Next ;shuffle array For $i = 1 To $shuffles $c1 = Random(1, $size, 1) Do $c2 = Random(1, $size, 1) Until $c1 <> $c2 _ArraySwap ( $aPack[$c1], $aPack[$c2] ) Next _ArrayDisplay($aPack) "be smart, drink your wine"
weaponx Posted June 17, 2007 Posted June 17, 2007 expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.1.1.0 Author: WeaponX Script Function: Populate array with playing cards, with functions for display and shuffle #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <Array.au3> Dim $CARDS[52][2] $FACES = _ArrayCreate ( "Clubs", "Hearts", "Diamonds", "Spades" ) $VALUES = _ArrayCreate ( "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queem", "King" ) createdeck() displaydeck() shuffledeck() displaydeck() Func createdeck() Dim $NUM = 0 ;Loop through faces For $X = 0 to 3 ;Loop through values For $Y = 0 to 12 $CARDS[$NUM][0] = $FACES[$X] $CARDS[$NUM][1] = $VALUES[$Y] $NUM += 1 Next Next EndFunc Func shuffledeck() Dim $TEMPCARD[1][2] ;Loop through deck For $X = 0 to 51 ;Generate random card element $R = Random ( 0 , 51 , 1 ) ;Read random card from deck $TEMPCARD[0][0] = $CARDS[$R][0] $TEMPCARD[0][1] = $CARDS[$R][1] ;Swap random card with current card $CARDS[$R][0] = $CARDS[$X][0] $CARDS[$R][1] = $CARDS[$X][1] ;Finish swap $CARDS[$X][0] = $TEMPCARD[0][0] $CARDS[$X][1] = $TEMPCARD[0][1] Next EndFunc Func displaydeck() Dim $MSG = "" ;Loop through deck For $X = 0 to 51 $MSG &= "$CARDS[" & $X & "][0] = " & $CARDS[$X][1] & " of " & $CARDS[$X][0] & @CRLF Next ;Display deck MsgBox(0,"", $MSG) $MSG = "" EndFunc
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now