-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·445 lines (381 loc) · 13.5 KB
/
index.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<!DOCTYPE html>
<html>
<head>
<title>FRC Stronghold 2016 Score Calculator</title>
<style type="text/css">
/*number inputs*/
input[type="number"] {
width:50px; height:30px;
text-align:center;
margin:3px;
float:left;}
/*select and equals elements*/
select, .equals {
margin:3px;
float:left;}
/*output element*/
output {
display:block;
border:1px solid #333333;
border-radius:5px;
min-width:25px; height:25px;
margin:3px; padding:2px;
text-align:center;
background:#000000;
color:#ffffff;
float:left; }
</style>
<script type="text/javascript">
// This function caluclates the current tower strength.
// Tower strength range [0-8]
// Returns current tower strength.
function calcTowerStrength()
{
// Get Form
var form = document.getElementById("calc");
// Get Ouput Field
var tower = form.elements["towerStrength"];
// Get Field Values
var lowBoulderTele = parseInt(form.elements["lowBoulderTele"].value);
var lowBoulderAlliance = parseInt(form.elements["lowBoulderAlliance"].value);
var highBoulderTele = parseInt(form.elements["highBoulderTele"].value);
var highBoulderAlliance = parseInt(form.elements["highBoulderAlliance"].value);
var boulderCount = lowBoulderTele + lowBoulderAlliance + highBoulderTele + highBoulderAlliance;
var strength = 8 - boulderCount;
if (strength < 0) {
strenght = 0;
tower.value = "0";
} else {
tower.value = strength;
}
return strength;
}
// This function updates the output text fields
function updateOutput() {
// Get form
var form = document.getElementById("calc");
// Get output
var out = form.elements["totalScore"];
// Get Values from the table
var reachDefenceAuto = parseInt(form.elements["reachDefenceAuto"].value);
var lowBoulderAuto = parseInt(form.elements["lowBoulderAuto"].value);
var lowBoulderTele = parseInt(form.elements["lowBoulderTele"].value);
var lowBoulderAlliance = parseInt(form.elements["lowBoulderAlliance"].value);
var highBoulderAuto = parseInt(form.elements["highBoulderAuto"].value);
var highBoulderTele = parseInt(form.elements["highBoulderTele"].value);
var highBoulderAlliance = parseInt(form.elements["highBoulderAlliance"].value);
var challengeTele = parseInt(form.elements["challengeTele"].value);
var scaleTele = parseInt(form.elements["scaleTele"].value);
var crossDefenceAuto = parseInt(form.elements["crossDefenceAuto"].value);
// Calculate Points
var reachDefence;
if (reachDefenceAuto > 1) {
reachDefence = 2;
} else {
reachDefence = (reachDefenceAuto * 2);
}
var crossDefence;
if (crossDefenceAuto > 1) {
crossDefence = calcDefenceDamage() * 10 + 10;
} else {
crossDefence = calcDefenceDamage() * 5 + (crossDefenceAuto * 10);
}
var lowBoulder = (lowBoulderAuto * 5) + (lowBoulderTele * 2);
var highBoulder = (highBoulderAuto * 10) + (highBoulderTele * 5);
var challenge = (challengeTele * 5);
var scale = (scaleTele * 15);
// Set Output Fields
out.value = reachDefence + crossDefence + lowBoulder + highBoulder + challenge + scale;
var towerStrength = calcTowerStrength();
calcCapture(towerStrength);
}
function calcReachingDefence()
{
// Get Form
var form = document.getElementById("calc");
// Get Inputs
var reachDefenceAuto = parseInt(form.elements["reachDefenceAuto"].value);
var reachDefenceAlliance = parseInt(form.elements["reachDefenceAlliance"].value);
var crossDefenceAuto = parseInt(form.elements["crossDefenceAuto"].value);
var reached = reachDefenceAuto + reachDefenceAlliance;
if (reached > 1) {
if (crossDefenceAuto > 0) {
return false;
} else {
return true;
}
} else {
return false;
}
}
// This function calculates the state of the defences.
// Return value is number of defencive damage done.
function calcDefenceDamage()
{
// Get Form
var form = document.getElementById("calc");
// Get Ouput Box
var defence = form.elements["defenceDamage"];
var breach = form.elements["breachOutput"];
// Get Input Values
var crossDefenceTele = parseInt(form.elements["crossDefenceTele"].value);
var crossDefenceAlliance = parseInt(form.elements["crossDefenceAlliance"].value);
var damage = crossDefenceTele + crossDefenceAlliance;
if (damage > 10) {
defence.value = "10";
return 10 - crossDefenceAlliance;
} else if (damage >= 8) {
defence.value = damage;
breach.value = "YES";
return damage - crossDefenceAlliance;
} else {
defence.value = damage;
breach.value = "NO";
return damage - crossDefenceAlliance;
}
}
// This function validates the inputs for the Reaching a Defence field.
function validateReachingDefence(t)
{
// Get Form
var form = document.getElementById("calc");
// Get Inputs
var reachDefenceAuto = parseInt(form.elements["reachDefenceAuto"].value);
var crossDefenceAuto = parseInt(form.elements["crossDefenceAuto"].value);
if (crossDefenceAuto > 0) {
t.value = "0";
}
updateOutput()
}
// This function validates the inputs for the Reaching a Defence field.
function validateCrossAuto(t)
{
// Get Form
var form = document.getElementById("calc");
// Get Inputs
var reachDefenceAuto = parseInt(form.elements["reachDefenceAuto"].value);
var crossDefenceAuto = parseInt(form.elements["crossDefenceAuto"].value);
if (crossDefenceAuto > 0) {
if (reachDefenceAuto > 0) {
form.elements["reachDefenceAuto"].value = "0";
}
}
updateOutput();
}
// This function validates the inputs for the Reaching a Defence field.
function validateCross(t)
{
if (t.value < 0)
t.value = "0";
updateOutput();
}
// This function validates the text form for the CHALLENGE input.
// Since a Challenge occurs when the robot hasn't scaled the tower
// we need to modify the Scale value appropriately.
function validateChallenge(t) {
var form = document.getElementById("calc");
scale = form.elements["scaleTele"];
scaleValue = parseInt(scale.value);
if (t.value < 0) {
t.value = "0";
}
else if (t.value == 1) {
if (scaleValue > 0) {
t.value = "1";
scale.value = "0";
}
}
else if (t.value > 1) {
t.value = "1";
}
updateOutput();
}
// This function validates the text form for the SCALE input.
// When a robot SCALES the tower they lose the points for challenge
// and gain the 15 for scaling.
function validateScale(t) {
var form = document.getElementById("calc");
challenge = form.elements["challengeTele"];
challengeValue = parseInt(challenge.value);
if (t.value < 0) {
t.value = "0";
}
else if (t.value == 1) {
if (challengeValue > 0) {
t.value = "1";
challenge.value = "0";
}
}
else if (t.value > 1) {
t.value = "1";
}
updateOutput();
}
// This function validates the input of the SCALE of the allicance member input.
function validateScaleAlliance(t)
{
if (t.value < 0) {
t.value = "0";
} else if (t.value > 2) {
t.value = "2";
}
updateOutput();
}
// This function validates the input of the CHALLENGE of the allicance member input.
function validateChallengeAlliance(t)
{
if (t.value < 0) {
t.value = "0";
} else if (t.value > 2) {
t.value = "2";
}
updateOutput();
}
// This functions verifies if we have achieved the CAPTURE action.
function calcCapture(towerStrength)
{
// Get Form
var form = document.getElementById("calc");
// Get Output
capture = form.elements["captureOutput"];
// Get Inputs
challengeTele = parseInt(form.elements["challengeTele"].value);
challengeAlliance = parseInt(form.elements["challengeAlliance"].value);
scaleTele = parseInt(form.elements["scaleTele"].value);
scaleAlliance = parseInt(form.elements["scaleAlliance"].value);
// We can only capture once the tower strength is 0.
if (towerStrength > 0) {
return false;
}
var count = challengeTele + challengeAlliance + scaleTele + scaleAlliance;
if (count >= 3) {
capture.value = "YES";
} else {
capture.value = "NO";
}
}
// This function validates the text form for the Boulder low/high fields.
// Value can't be lower then 0.
function validateBoulder(t) {
if (t.value < 0) {
t.value = "0";
}
updateOutput();
}
</script>
</head>
<body>
<p>This is a calculator the FRC Stronghold competition. Count how many actions are taken by the robot and see what the final score would be. Listing total score at the bottom.</p>
<form id="calc" >
<table width="800" border="1">
<tr>
<td valign="middle"><strong>Action</strong></td>
<td valign="middle"><strong>AUTO</strong></td>
<td valign="middle"><strong>TELEOP</strong></td>
<td valign="middle"> </td>
<td valign="middle"><strong>Qual.</strong></td>
<td valign="middle"><strong>Playoff</strong></td>
<td valign="middle"><strong>Other Teams</strong></td>
</tr>
<tr>
<td valign="middle">REACHING a DEFENCE</td>
<td><input name="reachDefenceAuto" oninput="validateReachingDefence(this)" min="0" max="1" type="number" value="0" />
*2</td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle"> </td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle"><input name="reachDefenceAlliance" oninput="validateReachingDefence(this)" type="number" min="0" max="2" value="0" /></td>
</tr>
<tr>
<td valign="middle">CROSSING an UNDAMAGED DEFENCE</td>
<td valign="middle"><input name="crossDefenceAuto" oninput="validateCrossAuto(this)" min="0" max="1" type="number" value="0" />
*10</td>
<td valign="middle"><input name="crossDefenceTele" oninput="validateCross(this)" type="number" min="0" max="10" value="0" />*5</td>
<td valign="middle"> </td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="crossDefenceAlliance" oninput="validateCross(this)" type="number" min="0" max="10" value="0" /></td>
</tr>
<tr>
<td valign="middle">BOULDER in Low TOWER GOAL</td>
<td valign="middle"><input name="lowBoulderAuto" oninput="validateBoulder(this)" type="number" min="0" max="99" value="0" />
*5</td>
<td valign="middle"><input name="lowBoulderTele" oninput="validateBoulder(this)" type="number" min="0" max="99" value="0" />*2</td>
<td valign="middle"> </td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="lowBoulderAlliance" oninput="validateBoulder(this)" type="number" min="0" max="99" value="0" /></td>
</tr>
<tr>
<td valign="middle">BOULDER in High TOWER GOAL</td>
<td valign="middle"><input name="highBoulderAuto" oninput="validateBoulder(this)" type="number" min="0" max="99" value="0" />*10</td>
<td valign="middle"><input name="highBoulderTele" oninput="validateBoulder(this)" type="number" min="0" max="99" value="0" />*5</td>
<td valign="middle"> </td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="highBoulderAlliance" oninput="validateBoulder(this)" type="number" min="0" max="99" value="0" /></td>
</tr>
<tr>
<td valign="middle">CHALLENGE (per ROBOT)</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="challengeTele" oninput="validateChallenge(this)" type="number" min="0" max="1" value="0" />*5</td>
<td valign="middle"> </td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="challengeAlliance" oninput="validateChallengeAlliance(this)" type="number" min="0" max="2" value="0" /></td>
</tr>
<tr>
<td valign="middle">SCALE (per ROBOT)</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="scaleTele" oninput="validateScale(this)" type="number" min="0" max="1" value="0" />*15</td>
<td valign="middle"> </td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td valign="middle"><input name="scaleAlliance" oninput="validateScaleAlliance(this)" type="number" min="0" max="2" value="0" /></td>
</tr>
<tr>
<td valign="middle">BREACH</td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle"> </td>
<td align="center" valign="middle">1 RP</td>
<td align="center" valign="middle">20</td>
<td align="center" valign="middle"> </td>
</tr>
<tr>
<td valign="middle">CAPTURE</td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle">-</td>
<td align="center" valign="middle"> </td>
<td align="center" valign="middle">1 RP</td>
<td align="center" valign="middle">25</td>
<td align="center" valign="middle"> </td>
</tr>
</table>
<p></p>
<table width="600" border="1">
<tr>
<td>Tower Strength</td>
<td><output name="towerStrength" for="x y">8</output></td>
<td>Defences Damaged</td>
<td><output name="defenceDamage" for="x y">0</output></td>
</tr>
<tr>
<td>BREACH</td>
<td><output name="breachOutput" for="x y">NO</output></td>
<td>CAPTURE</td>
<td><output name="captureOutput" for="x y">NO</output></td>
</tr>
</table>
<p></p>
<table width="200" border="1">
<tr>
<td>Total Score</td>
<td><output name="totalScore" for="x y">0</output></td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>