-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.php
More file actions
74 lines (58 loc) · 1.65 KB
/
game.php
File metadata and controls
74 lines (58 loc) · 1.65 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
68
69
70
71
72
73
74
<?php
$totalplays = 0;
$howmany = 1;
$bigpurse = 200;
$highpurse = $bigpurse;
$lowpurse = $bigpurse;
do{
if ($bigpurse > 0) {
// Setting the beginning variables for each game.
$purse = 20;
$beginpurse = $purse;
$win = 0.48649;
$bet = 1;
// Plays the game. Runs until we lose all our money, or we double our originial purse.
do {
// $spin gives us a random decimal value back between 0 and 1.
$spin = ((mt_rand(0,100000))/100000);
// If the spin is black (between 0 and .48649), we win. We add our bet to the purse.
// Else, we lose. We subtract our bet from the purse.
echo "Your current bet is {$bet}\n";
echo "You big purse is " . ($bigpurse-($beginpurse-$purse)) . PHP_EOL;
if($spin <= $win) {
$purse += $bet;
$bet = 1;
echo "You won! ";
} else {
$purse -= $bet;
echo "You lost! ";
$bet *= 2;
// Doubles the bet if we lose.
// Set to reflect common $75 max bid on most roulette tables
if($bet > $purse) {
$bet = $purse;
}
}
echo "Your current purse is {$purse}\n";
}while($purse > 0 && $purse < (2 * $beginpurse));
if($purse >= (2 * $beginpurse)) {
$bigpurse += ($purse - $beginpurse);
if($bigpurse > $highpurse) {
$highpurse = $bigpurse;
}
} else {
$bigpurse += ($purse - $beginpurse);
if($bigpurse < $lowpurse) {
$lowpurse = $bigpurse;
}
}
$totalplays++;
} else {
echo "You have no more money to bet.\n";
$totalplays = $howmany;
}
}while($totalplays < $howmany);
echo "Your final purse is {$bigpurse}\n";
echo "The lowest value of your purse was {$lowpurse}\n";
echo "The highest value of your purse was {$highpurse}\n";
?>