for a different approach, i use a "ripple" shuffle to simulate the way a person would shuffle a deck by hand (uses a Type def to store the card info and Deck array of idnums for the actual gameplay). Here's my basic cardgame template:
(appologies if this comes out in a wierd format...it's my first post!)
Const MAXCARDS = 52 Const MAXSHUFFLE = 7 Local i Type tCard Field idnum Field suit$ Field value End Type Global CardDeck.tCard Dim Deck(MAXCARDS) ;holds the idnum of cards...used in actual gameplay Dim LeftHalf(MAXCARDS) ;holds the cards for shuffling from the "left hand" Dim RightHalf(MAXCARDS) ;holds the cards for shuffling from the "right hand" SeedRnd MilliSecs() LoadCardDeck() ;load card info into the Type def ResetDeck() ;reset Deck() to initial order CheckDeck("unshuffled.txt") ;output unshuffled deck to check cards ShuffleDeck(MAXCARDS) ;shuffle all cards CheckDeck("shuffled.txt") ;output shuffled deck to check cards Notify "Done" End Function ShuffleDeck(shufflecnt) ;shuffle deck routine Local curcard, leftcnt, rightcnt, incleft, incright, cutcnt leftcnt = Int(shufflecnt / 2) + Rand(-5,5) ;get half +/- 5 cards for left hand rightcnt = Int(shufflecnt - leftcnt) ;remainder goes into right hand Dim LeftHalf(leftcnt) ;re-dim just in case Dim RightHalf(rightcnt) ;actual shuffle loop For x = 1 To MAXSHUFFLE For i = 1 To leftcnt ;load lefthalf from Deck() LeftHalf(i) = Deck(i) Next For i = 1 To rightcnt ;load righthalf from Deck() RightHalf(i) = Deck(leftcnt + i) Next ;shuffle lefthalf & righthalf back into Deck() (overwrites whats already in Deck()) curcard = 0 incleft = 0 incright = 0 Repeat If x Mod 2 = 0 ;even iteration, start with lefthalf For y = 1 To Rand(3) ;pull up to 3 cards from lefthalf incleft = incleft + 1 If incleft > leftcnt Then Exit ;exit if ran out of lefthalf curcard = curcard + 1 Deck(curcard) = LeftHalf(incleft) ;overwrite Deck() with cards pulled back Next For y = 1 To Rand(3) ;now pull up to 3 cards from righthalf incright = incright + 1 If incright > rightcnt Then Exit ;exit if ran out of righthalf curcard = curcard + 1 Deck(curcard) = RightHalf(incright) ;overwrite Deck() with cards pulled back Next Else ;odd iteration, start with righthalf... For y = 1 To Rand(3) ;...do as above... incright = incright + 1 If incright > rightcnt Then Exit curcard = curcard + 1 Deck(curcard) = RightHalf(incright) Next For y = 1 To Rand(3) incleft = incleft + 1 If incleft > leftcnt Then Exit curcard = curcard + 1 Deck(curcard) = LeftHalf(incleft) Next EndIf Until curcard >= shufflecnt Next End Function Function LoadCardDeck() ;currently creates a normal deck of 52 cards (less jokers) Local i For i = 1 To MAXCARDS CardDeck = New tCard CardDeck\idnum = i Select True Case i >= 1 And i <= 13 CardDeck\suit$ = "Spades" CardDeck\value = i Case i >= 14 And i <= 26 CardDeck\suit$ = "Hearts" CardDeck\value = i-13 Case i >= 27 And i <= 39 CardDeck\suit$ = "Clubs" CardDeck\value = i-26 Case i >= 40 And i <= 52 CardDeck\suit$ = "Diamonds" CardDeck\value = i-39 End Select Next End Function Function ResetDeck() ;reset the deck array into it's original order Local i For i = 1 To MAXCARDS ;Deck() is full and in original order Deck(i) = i Next End Function Function GetCard.tCard(cardnum) ;go to cardnum (for pulling card info) For theCard.tCard = Each tCard If theCard\idnum = cardnum Then Return theCard Next Return Null End Function Function CheckDeck(outputfilename$) ;output deck just for debug purposes FileOut = WriteFile(outputfilename$) For i = 1 To MAXCARDS CardDeck.tCard = GetCard(Deck(i)) WriteLine(FileOut,CardDeck\idnum + ":" + CardDeck\suit$ + "-" + CardDeck\value) Next CloseFile FileOut End Function
(appologies if this comes out in a wierd format...it's my first post!)