playable game and stats
This commit is contained in:
parent
57503c732d
commit
a62644f705
10
README.md
10
README.md
|
@ -1 +1,11 @@
|
|||
Simple card game.
|
||||
|
||||
# Usage
|
||||
|
||||
`./play.bash`
|
||||
|
||||
Play a single game.
|
||||
|
||||
`./stats.bash`
|
||||
|
||||
Play a number of games and look at the stats.
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#!/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
|
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# ./stats.bash
|
||||
# or
|
||||
# ./stats.bash NUM_SIMULATIONS
|
||||
|
||||
for ((i=0; i < ${1:-1000}; i++))
|
||||
do
|
||||
./play.bash
|
||||
done | awk '
|
||||
/^\w+ vinner!$/ {
|
||||
win[$1]++
|
||||
}
|
||||
/^Uavgjort\.\.\.$/ {
|
||||
tie++
|
||||
}
|
||||
|
||||
END {
|
||||
for(i in win) {
|
||||
printf "%s vant %d ganger.\n", i, (win[i] ? win[i] : 0)
|
||||
}
|
||||
print "Det ble uavgjort", (tie ? tie : 0), "ganger."
|
||||
}
|
||||
'
|
Loading…
Reference in New Issue