suits.sh 792 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. declare -a color=("spade" "heart" "club" "diamond")
  3. declare -a point=("A" "2" "3" "4" "5" "6" "7" "8" "9" "10" "J" "Q" "K")
  4. function seed_random() {
  5. local min=$1
  6. local max=$2
  7. seq $1 $2 | shuf -n $(($2-$1+1))
  8. }
  9. function deal_cards() {
  10. local cards=$1
  11. local beg=$2
  12. local end=$3
  13. local cnt=0
  14. for i in $cards
  15. do
  16. if [ $cnt -eq $end ];then
  17. return
  18. fi
  19. if [ $cnt -ge $beg ];then
  20. printf ${color[$(($i%4))]}${point[$(($i%13))]}" "
  21. fi
  22. cnt=$(($cnt+1))
  23. done
  24. }
  25. function main() {
  26. card_idx=$(seed_random 0 51)
  27. printf "first one: "
  28. deal_cards "$card_idx" 0 13
  29. printf "\nsecond one: "
  30. deal_cards "$card_idx" 13 26
  31. printf "\nthird one: "
  32. deal_cards "$card_idx" 26 39
  33. printf "\nfourth one: "
  34. deal_cards "$card_idx" 39 52
  35. }
  36. main