UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: kevin on August 02, 2010, 09:40:19 AM

Title: Shuffle Deck Of cards
Post by: kevin on August 02, 2010, 09:40:19 AM
 Shuffle Deck Of cards



[pbcode]
   ; Dim array to hold the Deck
   Dim Deck(52)

   ; seed the card array from 1 to 52
   For lp=1 to 52
       Deck(lp)=lp
   next

   ; Shuffle the card array
    Shuffle(2)

   ; Display cards
   For lp=1 to 52
      Card=Deck(lp)
      row$+=str$(Card)
      count++
      if count=4
         print row$
         Count=0
         Row$=""
      else
         Row$+=","
      endif
   next

   ;
   Sync
   WaitKEY



Function Shuffle(Passes)
   for pass=1 to passes
      For lp=1 to 52
         pos=rndrange(1,52)

         Temp1=Deck(lp)
         Temp2=Deck(pos)

         Deck(pos)=Temp1
         Deck(lp)=Temp2

      next
   next   
EndFunction

[/pbcode]