Rewrite the rps module. It is buggy.

This commit is contained in:
Storm Dragon 2016-09-03 02:24:14 -04:00
parent ed0fbcb89b
commit 0178eb057f

View File

@ -1,32 +1,35 @@
#!/bin/bash
# 0 - rock
# 1 - paper
# 2 - scissor
[ -f functions.sh ] && source functions.sh
cpu="$(shuf -n 1 -e PAPER ROCK SCISSORS)"
player="$3"
m_choice=$(($RANDOM%3))
o_choice=$(echo $3 | sed -r "s/^[rR].*/0/" | sed -r "s/^[pP].*/1/" | sed -r "s/^[sS].*/2/")
#convert my random to either r/p/s
case "$m_choice" in
0)
mr_choice="rock"
case "${player^^}" in
R|RO|ROC|ROCK)
player="ROCK"
;;
1)
mr_choice="paper"
P|PA|PAP|PAPE|PAPER)
player="PAPER"
;;
2)
mr_choice="scissor"
S|SC|SCI|SCIS|SCISS|SCISSO|SCISSOR|SCISSORS)
player="SCISSORS"
;;
*)
player="INVALID"
esac
if [ "$m_choice" == "$o_choice" ]
then
outcome="tie"
elif [ "$((($m_choice+1)%3))" == "$o_choice" ]
then
outcome="lose"
if [ "$player" = "INVALID" ]; then
msg "$2" "$1: Please select PAPER, ROCK, or SCISSORS."
elif [ "$cpu" = "$player" ]; then
msg "$2" "$1: You and I both selected $player, so we tied."
elif [ "$cpu" = "PAPER" && "$player" != "SCISSORS" ]; then
msg "$2" "$1: my $CPU beats your $player!"
elif [ "$cpu" = "ROCK" && "$player" != "PAPER" ]; then
msg "$2" "$1: my $CPU beats your $player!"
elif [ "$cpu" = "SCISSORS" && "$player" != "ROCK" ]; then
msg "$2" "$1: my $CPU beats your $player!"
elif [ "$player" = "PAPER" && "$cpu" != "SCISSORS" ]; then
msg "$2" "$1: your $player beats my $cpu!"
elif [ "$player" = "ROCK" && "$cpu" != "PAPER" ]; then
msg "$2" "$1: your $player beats my $cpu!"
else
outcome="win"
msg "$2" "$1: your $player beats my $cpu!"
fi
echo "PRIVMSG $2 :$1: $3 VS $mr_choice | I $outcome!"