Not sure if this is the correct forum but I thought I'd share a very simple BASH script (Linux) to simulate a 52 card deck shuffle and dealing to a number of players in a Texas hold 'em game. The purpose is to replace manual shuffling and dealing for running simulations.
A similar Online tool
(I was specifically looking for a UNIX terminal tool hence the hobby project)
-
https://www.random.org/playing-cards/
Disclaimer: I am not a professional programmer so if there are any bugs or features missing, you are mostly on your own.
Currently the output format is written for a simulation of shuffle and dealing to 1, 2, 9 and 10 players only. I haven't written the output for 3-9 players situation and the script will throw an error for this condition.
Dependencies
- Linux OS (Haven't tested on UNIX)
- /usr/bin/bash (BASH)
- shuf program (part of GNU coreutils)
Almost all Linux distributions have the above dependencies installed.
Instructions.
1. Copy and paste bellow output into a new file. Save the file as "Cards.txt".
Name and case matters.
Code:
Ac
As
Ah
Ad
Kc
Ks
Kh
Kd
Qc
Qs
Qh
Qd
Jc
Js
Jh
Jd
Tc
Ts
Th
Td
9c
9s
9h
9d
8c
8s
8h
8d
7c
7s
7h
7d
6c
6s
6h
6d
5c
5s
5h
5d
4c
4s
4h
4d
3c
3s
3h
3d
2c
2s
2h
2d
2. Copy and paste bellow output into a new file. Save the file as shuffle_up_and_deal.sh
Name doesn't matter as long as you can find it.
Code:
#!/usr/bin/bash
SHUFFLED_DECK_ARRAY=($(shuf Cards.txt))
clear
echo ""
echo "Welcome to Shuffle Up and Deal simulation."
echo ""
echo -n "Enter how many players you would like to deal in [9]: "
read NUMBER_OF_PLAYERS
NUMBER_OF_PLAYERS=${NUMBER_OF_PLAYERS:-9}
if [[ "$NUMBER_OF_PLAYERS" -gt 10 || "$NUMBER_OF_PLAYERS" -lt 1 ]]; then
echo ""
echo "Error. You must set number of players between 1 and 10."
echo "Press the ENTER key to exit and try again ..."
read PAUSE
exit
fi
echo ""
echo -n "Enter how many shuffles you would like to do [10]: "
read NUMBER_OF_SHUFFLES
NUMBER_OF_SHUFFLES=${NUMBER_OF_SHUFFLES:-10}
if [[ "$NUMBER_OF_SHUFFLES" -lt 1 ]]; then
echo ""
echo "Error. You must do at least 1 shuffle."
echo "Press the ENTER key to exit and try again ..."
read PAUSE
exit
fi
echo ""
echo "OK, now shuffling and dealing players in... "
echo "Press the ENTER key to continue"
read PAUSE
SHUFFLE=1
if [[ "$NUMBER_OF_PLAYERS" -eq 10 ]]; then
while [[ "$NUMBER_OF_SHUFFLES" -gt 0 ]]
do
clear
echo "Hand #"$SHUFFLE""
echo ""
echo "My hand Flop Turn River"
echo -n "${SHUFFLED_DECK_ARRAY[0]} "
echo -n "${SHUFFLED_DECK_ARRAY[1]}"
echo " ${SHUFFLED_DECK_ARRAY[@]0:49} ${SHUFFLED_DECK_ARRAY[48]} ${SHUFFLED_DECK_ARRAY[47]}"
echo ""
echo ""
echo -n "${SHUFFLED_DECK_ARRAY[2]} "
echo "${SHUFFLED_DECK_ARRAY[3]}"
echo -n "${SHUFFLED_DECK_ARRAY[4]} "
echo "${SHUFFLED_DECK_ARRAY[5]}"
echo -n "${SHUFFLED_DECK_ARRAY[6]} "
echo "${SHUFFLED_DECK_ARRAY[7]}"
echo -n "${SHUFFLED_DECK_ARRAY[8]} "
echo "${SHUFFLED_DECK_ARRAY[9]}"
echo -n "${SHUFFLED_DECK_ARRAY[10]} "
echo "${SHUFFLED_DECK_ARRAY[11]}"
echo -n "${SHUFFLED_DECK_ARRAY[12]} "
echo "${SHUFFLED_DECK_ARRAY[13]}"
echo -n "${SHUFFLED_DECK_ARRAY[14]} "
echo "${SHUFFLED_DECK_ARRAY[15]}"
echo -n "${SHUFFLED_DECK_ARRAY[16]} "
echo "${SHUFFLED_DECK_ARRAY[17]}"
echo -n "${SHUFFLED_DECK_ARRAY[18]} "
echo "${SHUFFLED_DECK_ARRAY[19]}"
echo ""
echo ""
let NUMBER_OF_SHUFFLES=$NUMBER_OF_SHUFFLES-1
if [[ "$NUMBER_OF_SHUFFLES" -eq 0 ]]; then
echo ""
echo "No more shuffles to do"
echo "Press the ENTER key to quit the game"
read PAUSE
echo
exit
fi
let SHUFFLE=$SHUFFLE+1
echo -n "Press the ENTER key to continue to next shuffle..."
read PAUSE
SHUFFLED_DECK_ARRAY=($(shuf Cards.txt))
done
fi
if [[ "$NUMBER_OF_PLAYERS" -eq 9 ]]; then
while [[ "$NUMBER_OF_SHUFFLES" -gt 0 ]]
do
clear
echo "Hand #"$SHUFFLE""
echo ""
echo "My hand Flop Turn River"
echo -n "${SHUFFLED_DECK_ARRAY[0]} "
echo -n "${SHUFFLED_DECK_ARRAY[1]}"
echo " ${SHUFFLED_DECK_ARRAY[@]0:49} ${SHUFFLED_DECK_ARRAY[48]} ${SHUFFLED_DECK_ARRAY[47]}"
echo ""
echo ""
echo -n "${SHUFFLED_DECK_ARRAY[2]} "
echo "${SHUFFLED_DECK_ARRAY[3]}"
echo -n "${SHUFFLED_DECK_ARRAY[4]} "
echo "${SHUFFLED_DECK_ARRAY[5]}"
echo -n "${SHUFFLED_DECK_ARRAY[6]} "
echo "${SHUFFLED_DECK_ARRAY[7]}"
echo -n "${SHUFFLED_DECK_ARRAY[8]} "
echo "${SHUFFLED_DECK_ARRAY[9]}"
echo -n "${SHUFFLED_DECK_ARRAY[10]} "
echo "${SHUFFLED_DECK_ARRAY[11]}"
echo -n "${SHUFFLED_DECK_ARRAY[12]} "
echo "${SHUFFLED_DECK_ARRAY[13]}"
echo -n "${SHUFFLED_DECK_ARRAY[14]} "
echo "${SHUFFLED_DECK_ARRAY[15]}"
echo -n "${SHUFFLED_DECK_ARRAY[16]} "
echo "${SHUFFLED_DECK_ARRAY[17]}"
echo ""
echo ""
let NUMBER_OF_SHUFFLES=$NUMBER_OF_SHUFFLES-1
if [[ "$NUMBER_OF_SHUFFLES" -eq 0 ]]; then
echo ""
echo "No more shuffles to do"
echo "Press the ENTER key to quit the game"
read PAUSE
echo
exit
fi
let SHUFFLE=$SHUFFLE+1
echo -n "Press the ENTER key to continue to next shuffle..."
read PAUSE
SHUFFLED_DECK_ARRAY=($(shuf Cards.txt))
done
fi
if [[ "$NUMBER_OF_PLAYERS" -eq 2 ]]; then
while [[ "$NUMBER_OF_SHUFFLES" -gt 0 ]]
do
clear
echo "Hand #"$SHUFFLE""
echo ""
echo "My hand Flop Turn River"
echo -n "${SHUFFLED_DECK_ARRAY[0]} "
echo -n "${SHUFFLED_DECK_ARRAY[1]}"
echo " ${SHUFFLED_DECK_ARRAY[@]0:49} ${SHUFFLED_DECK_ARRAY[48]} ${SHUFFLED_DECK_ARRAY[47]}"
echo ""
echo ""
echo -n "${SHUFFLED_DECK_ARRAY[2]} "
echo "${SHUFFLED_DECK_ARRAY[3]}"
echo ""
echo ""
let NUMBER_OF_SHUFFLES=$NUMBER_OF_SHUFFLES-1
if [[ "$NUMBER_OF_SHUFFLES" -eq 0 ]]; then
echo ""
echo "No more shuffles to do"
echo "Press the ENTER key to quit the game"
read PAUSE
echo
exit
fi
let SHUFFLE=$SHUFFLE+1
echo -n "Press the ENTER key to continue to next shuffle..."
read PAUSE
SHUFFLED_DECK_ARRAY=($(shuf Cards.txt))
done
fi
if [[ "$NUMBER_OF_PLAYERS" -eq 1 ]]; then
while [[ "$NUMBER_OF_SHUFFLES" -gt 0 ]]
do
clear
echo "Hand #"$SHUFFLE""
echo ""
echo "My hand Flop Turn River"
echo -n "${SHUFFLED_DECK_ARRAY[0]} "
echo -n "${SHUFFLED_DECK_ARRAY[1]}"
echo " ${SHUFFLED_DECK_ARRAY[@]0:49} ${SHUFFLED_DECK_ARRAY[48]} ${SHUFFLED_DECK_ARRAY[47]}"
echo ""
echo ""
let NUMBER_OF_SHUFFLES=$NUMBER_OF_SHUFFLES-1
if [[ "$NUMBER_OF_SHUFFLES" -eq 0 ]]; then
echo ""
echo "No more shuffles to do"
echo "Press the ENTER key to quit the game"
read PAUSE
echo
exit
fi
let SHUFFLE=$SHUFFLE+1
echo -n "Press the ENTER key to continue to next shuffle..."
read PAUSE
SHUFFLED_DECK_ARRAY=($(shuf Cards.txt))
done
fi
if [[ "$NUMBER_OF_PLAYERS" -gt 2 ]] && [[ "$NUMBER_OF_PLAYERS" -lt 9 ]] ; then
clear
echo ""
echo "Modify script to display entries for 3 - 9 players."
echo "Press the ENTER key to exit..."
read PAUSE
echo ""
exit
fi
exit
3. Make sure that "Cards.txt" file and "shuffle_up_and_deal.sh" file are both in the same directory.
4. To run simply execute $ sh shuffle_up_and_deal.sh in a Linux (virtual) terminal.
Hope you enjoy it and find it useful.
Last edited by _dave_; 07-24-2016 at 03:13 AM.
Reason: code tags ffs