Advertisement
T3RRYT3RR0R

Card dealer

Jul 17th, 2022 (edited)
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.25 KB | None | 0 0
  1. @Echo off
  2.     Setlocal EnableDelayedExpansion
  3.  
  4. REM initialize reference strings
  5. REM Ace at array indices 49 - 52 to allow exclusion
  6.     Set "Type[11]=Jack"
  7.     Set "Type[12]=Queen"
  8.     Set "Type[13]=King"
  9.     Set "Type[14]=Ace"
  10.  
  11. Rem Assign starting values
  12.     Set "Count=0"
  13.     Set "Deck="
  14.  
  15. Rem Define Deck List and Card Array
  16.     For %%n in (Hearts Diamonds Clubs Spades)Do (
  17.         For /l %%i in (2 1 14)Do (
  18.             Set /A Count+=1
  19.             Set "Deck=!Deck! !Count!,"
  20.             If defined Type[%%i] (
  21.                 Set "Card[!Count!]=!Type[%%i]!  of %%n"
  22.             )Else (
  23.                 Set "Card[!Count!]=%%i  of %%n"
  24.             )
  25.         )
  26.     )
  27.  
  28.  
  29. Rem call deal function for number of 'players', deal a number of cards
  30.     For /L %%n in (1 1 3)Do (
  31.         For /l %%i in (1 1 5)Do Call:Deal Player[%%n][%%i] && Echo(Player %%n  Card %%i: !Player[%%n][%%i]!
  32.         Echo(
  33.     )
  34.  
  35.  Endlocal & Goto:Eof
  36.  
  37.  :Deal <returnVar>
  38. REM flag if entire deck has been dealt
  39.     If "!Deck!"=="" Exit /B 1
  40.  
  41. REM select random array index from all possible cards
  42.     Set /A Rand=!Random! %%52 + 1
  43.  
  44. REM test if selected index has been dealt previously
  45.     If not "!Deck: %Rand%,=!"=="!Deck!" (
  46.     REM 'deal' card.
  47.         Set "Deck=!Deck: %Rand%,=!"
  48.         Set "%1=!Card[%Rand%]!" || Echo(missing arg 1.
  49.         Exit /B 0
  50.     )Else (
  51.     REM select new index
  52.         Goto:Deal
  53.     )
  54. Exit /B 1
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement