forked from jatloe/RandomWebsite1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2048_calculator.html
106 lines (99 loc) · 3.95 KB
/
2048_calculator.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="jatloesmile-hd.png">
<title>2048 Probability Calculator</title>
<style>
.side {
display: inline;
}
</style>
</head>
<body>
<p class="side">4 spawn probability:</p>
<input type="text" id="spawnrate" size="3" maxlength="3" value="10" class="side">
<p class="side">%</p>
<br>
<div id="s1p1" class="side">
<input type="text" id="numer1" size="2" maxlength="2" value="1" class="side">
<p class="side">/</p>
<input type="text" id="denom1" size="2" maxlength="2" value="1" class="side">
<select id="tile1">
<option value="None">-</option>
<option value="Both">Both</option>
<option value="2">2</option>
<option value="4">4</option>
</select>
</div>
<div id="s1p2" class="side" style="display:none;">
<p class="side">-></p>
<input type="text" id="numer2" size="2" maxlength="2" value="1" class="side">
<p class="side">/</p>
<input type="text" id="denom2" size="2" maxlength="2" value="1" class="side">
<select id="tile2">
<option value="None">-</option>
<option value="Both">Both</option>
<option value="2">2</option>
<option value="4">4</option>
</select>
</div>
<div id="s1p3" class="side" style="display:none;">
<p class="side">-></p>
<input type="text" id="numer3" size="2" maxlength="2" value="1" class="side">
<p class="side">/</p>
<input type="text" id="denom3" size="2" maxlength="2" value="1" class="side">
<select id="tile3">
<option value="None">-</option>
<option value="Both">Both</option>
<option value="2">2</option>
<option value="4">4</option>
</select>
</div>
<div id="s1p4" class="side" style="display:none;">
<p class="side">-></p>
<input type="text" id="numer4" size="2" maxlength="2" value="1" class="side">
<p class="side">/</p>
<input type="text" id="denom4" size="2" maxlength="2" value="1" class="side">
<select id="tile4">
<option value="None">-</option>
<option value="Both">Both</option>
<option value="2">2</option>
<option value="4">4</option>
</select>
</div>
<div id="s1p5" class="side" style="display:none;">
<p class="side">-></p>
<input type="text" id="numer5" size="2" maxlength="2" value="1" class="side">
<p class="side">/</p>
<input type="text" id="denom5" size="2" maxlength="2" value="1" class="side">
<select id="tile5">
<option value="None">-</option>
<option value="Both">Both</option>
<option value="2">2</option>
<option value="4">4</option>
</select>
</div>
<br>
<p id="prob">Probability: 100%</p>
</body>
<script>
setInterval(update, 50);
for (let i = 1; i < 5; i++) {
let input = document.getElementById("tile" + i.toString());
input.addEventListener('click', function() {
if (input.selectedIndex != 0) {
document.getElementById("s1p" + (i + 1).toString()).style.display = "";
}
});
}
function update() {
let probability = 1;
for (let i = 1; i <= 5; i++) {
if (document.getElementById("s1p" + i.toString()).style.display != "none") {
probability *= parseInt(document.getElementById("numer" + i.toString()).value) / parseInt(document.getElementById("denom" + i.toString()).value) * [1, 1, 1 - parseInt(document.getElementById("spawnrate").value) / 100, parseInt(document.getElementById("spawnrate").value) / 100][document.getElementById("tile" + i.toString()).selectedIndex];
}
}
document.getElementById("prob").innerHTML = "Probability: " + Math.round(probability * 100000) / 1000 + "%";
}
</script>
</html>