cardgame/play.bash

39 lines
869 B
Bash
Executable File

#!/usr/bin/env bash
# ./play.bash
alice_sum=0
bob_sum=0
round=0
# prize deck is random
# alice's hand is identical to prize deck
# bob's hand is random
while read -r prize bob_bet
do
printf 'Runde %s: Premie er %s, Alice satser %s, Bob satser %s.\n' \
"$((++round))" "$prize" "$prize" "$bob_bet"
if ((prize > bob_bet))
then
((alice_sum += prize))
printf 'Alice vinner %s!\n' "$prize"
elif ((bob_bet > prize))
then
((bob_sum += prize))
printf 'Bob vinner %s!\n' "$prize"
else
printf 'Ingen vinner denne runden...\n'
fi
done < <(paste <(shuf deck) <(shuf deck))
printf 'Spillet er over!\nAlice: %s\nBob: %s\n' "$alice_sum" "$bob_sum"
if ((alice_sum > bob_sum))
then
printf 'Alice vinner!\n'
elif ((bob_sum > alice_sum))
then
printf 'Bob vinner!\n'
else
printf 'Uavgjort...\n'
fi