-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamblingSimulation.sh
executable file
·64 lines (57 loc) · 1.16 KB
/
gamblingSimulation.sh
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
#!/bin/bash -x
#CONSTANTS
readonly WIN=1
readonly LOSE=0
readonly MAXWON=150 #maximum won amount limit
readonly RESAMT=50 #resign amount
#VARIABLES
totalAmtWon=0 #total amount won
totalAmtLost=0
daysWon=0
daysLost=0
dayCounter=1
betCounter=1
function gamble(){
if (( $chance==$WIN ))
then
return 1
else
return 0
fi
}
for (( dayCounter=1 ; dayCounter<=20 ; dayCounter++ ))
do
gambleAmount=100 #total gamble amount
while (( ($gambleAmount<$MAXWON) && ($gambleAmount>$RESAMT) ))
do
chance=$((RANDOM%2))
if (( $chance==$WIN ))
then
(( gambleAmount++ ))
else
(( gambleAmount-- ))
fi
done
if ((gambleAmount==RESAMT))
then
echo "YOU LOST: AMOUNT IS:" $gambleAmount
(( daysLost++ ))
totalAmtLost=$(( totalAmtLost+gambleAmount ))
echo "UNLUCKY DAY"
else
echo "YOU WON: AMOUNT IS:" $gambleAmount
(( daysWon++ ))
totalAmtWon=$(( totalAmtWon+gambleAmount ))
echo "LUCKY DAY"
fi
done
echo "total amt won:" $totalAmtWon
echo "No. of Days Won:" $daysWon
echo "total amt lost:" $totalAmtLost
echo "No. of Days Lost:" $daysLost
if ((totalAmtWon>2000)) #totalAmtWon>totalamountspentin20days
then
echo "Continue playing"
else
echo "Stop gamblig"
fi