forked from FAForever/patchnotes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmass-equivalent-calculator.html
81 lines (72 loc) · 2.43 KB
/
mass-equivalent-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
<!doctype html>
<title>Mass equivalent calculator</title>
<style>
td { padding: 0px 10px; }
#fixed1, #fixed2 { background: #DDD; }
#calculate {
padding: 8px 15px;
margin-left: 20px;
}
</style>
Type the mass cost of your units and press Calculate. For example Percy (1280 mass) vs Harbinger (840 mass).<p>
<table>
<tr>
<td><input id="mass1" value="1280"></td>
<td>vs</td>
<td><input id="mass2" value="840"></td>
<td rowspan="2"><button id="calculate">Calculate</button></td>
</tr>
<tr>
<td><input id="fixed1" value="0"></td>
<td></td>
<td><input id="fixed2" value="0"></td>
</tr>
</table>
<p>The grey fields are for setting fixed costs. For example if you want to count the cost of a T3 HQ for testing Harbringers vs Pillars, you enter the cost of the HQ under the Harbringers. Or if you want to test UEF battleships vs Cybran battleships, and add 5 shields to your UEF battleships, you write 5*1300 under the UEF battleships. <a href="#" id="load-example">Show example</a>
<br><br>
<table id="results"></table>
<script>
var fixed1input = document.getElementById("fixed1");
var fixed2input = document.getElementById("fixed2");
var mass1input = document.getElementById("mass1");
var mass2input = document.getElementById("mass2");
var resultsTable = document.getElementById("results");
function calculate()
{
var fixed1 = eval(fixed1input.value);
var fixed2 = eval(fixed2input.value);
var mass1 = eval(mass1input.value);
var mass2 = eval(mass2input.value);
var n=1; var k=1;
var results = [];
var mindev = 100;
for(var count=0; count<2000 && results.length < 100; count++){
var total1 = fixed1+mass1*n;
var total2 = fixed2+mass2*k;
var avg = (total1 + total2)/2;
var diff = total1 - total2;
var dev = diff/avg;
if(Math.abs(dev) < mindev && Math.abs(diff) < Math.min(mass1,mass2)) {
results.push("<tr><td>" + n + "</td><td>vs</td><td>" + k + "</td><td>(" + (100*dev).toFixed(2) + "%)</td></tr>");
}
mindev = Math.min(Math.abs(dev),mindev);
if(total1 < total2) n++;
else k++;
}
resultsTable.innerHTML = results.join("");
}
fixed1input.onchange = calculate;
fixed2input.onchange = calculate;
mass1input.onchange = calculate;
mass2input.onchange = calculate;
document.getElementById("calculate").onclick = calculate;
calculate()
document.getElementById("load-example").onclick = function()
{
mass1input.value = "10500";
fixed1input.value = "5*1300"
mass2input.value = "8000";
fixed2input.value = "0";
calculate();
}
</script>