用shell写出一个简单的猜拳游戏,枚举值(0石头,1剪刀,2步),有两位选手分别是rob1、rob2,他们出拳方式由系统自动枚举,并连续猜十次,最后给出十次结果
#!/bin/bash
# 统计猜拳次数
i=1
while (($i!=11))
do
# 出拳方式系统自动枚举
rob1=$(($RANDOM%3))
rob2=$(($RANDOM%3))
# 列举不同的出拳方式
if (($rob1==0));then
if (($rob2==0));then
echo "平局"
elif (($rob2==1));then
echo "rob1 胜"
else
echo "rob2 胜"
fi
elif (($rob1==1));then
if (($rob2==0));then
echo "rob2 胜"
elif (($rob2==1));then
echo "平局"
else
echo "rob1 胜"
fi
else
if (($rob2==0));then
echo "rob1 胜"
elif (($rob2==1));then
echo "rob2 胜"
else
echo "平局"
fi
fi
# 循环一次次数加一
((i++))
done