-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGamblingSimulator.sh
More file actions
executable file
·67 lines (62 loc) · 1.62 KB
/
GamblingSimulator.sh
File metadata and controls
executable file
·67 lines (62 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash -x
#constants for gambling simulation
EVERY_DAY_START_STAKE=100
BET=1
echo -e "Welcome to Gambling Simulator\n----------------------------"
echo -e "Every day Gambler can start with \$100\nEvery game you can bet \$1\n----------------------------"
stakeWin=0
stakeLost=0
dayWin=0
dayLost=0
f=1
while((f==1))
do
for(( i=1 ; i<=20 ; i++ ))
do
startStake=$EVERY_DAY_START_STAKE
stake=$startStake
noOfBets=0
resignWin=$((startStake+startStake/2))
resignLost=$((startStake/2))
while(( (stake<resignWin) && (stake>resignLost) ))
do
((noOfBets++))
randBet=$((RANDOM%2))
if ((randBet==1))
then
stake=$((stake+BET))
else
stake=$((stake-BET))
fi
done
if((stake==resignWin))
then
stakeWin=$((stakeWin+stake))
echo -e "You Won for the day $i = lucky day"
#echo "You played $noOfBets Bets to have stake = \$$stake"
echo -e "Total amount Won = \$$stake\n"
((dayWin++))
else
stakeLost=$((stakeLost+stake))
echo -e "You Lost for the day $i = Unlucky day"
#echo "You played $noOfBets Bets to have stake = \$$stake"
echo -e "Total amount Lost = \$$stake\n"
((dayLost++))
fi
done
echo -e "------------------------\nAfter a month\n-----------------------"
echo -e "No of days you won the game = $dayWin days\nTotal amount Won = $stakeWin"
echo -e "No of days you lost the game = $dayLost days\nTotal amount Lost = $stakeLost"
result=$((dayWin*50-dayLost*50))
if((result>0))
then
echo "You Won for the month. Would you like to continue (y/n) : "
read continue
if [[ $continue == 'n' ]]
then f=0
fi
else
echo "You lost this month. You have to stop"
f=0
fi
done