-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFauxHollows.html
627 lines (474 loc) · 12.5 KB
/
FauxHollows.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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<!DOCTYPE html>
<html>
<head>
<style>
td{
text-align: center;
}
select{
width: 50px;
height:50px;
}
p{
vertical-align: middle;
}
.container.hiddenSection{
display:none;
}
.btn.square
{
width: 50px;
height:50px;
display: inline-block;
margin: 1px;
border: 2px solid grey;
}
.selectorSection{
margin-right: 10px;
align-self:center;
display:flex;
flex-direction:column;
}
.selectorRow{
margin:2px;
}
.btn{
display:flex
}
.btn.addBorder{
border: 2px solid gray;
border-collapse:collapse;
}
.message{
border: 3px solid blueviolet;
border-collapse:collapse;
background-color: beige;
text-emphasis: form;
}
.selected.addBorder{
border: 2px solid green;
border-collapse:collapse;
}
.container {
display: flex;
justify-content: center;
}
.btn.bestMatch {
border: 3px solid green;
}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script>
"use strict";
function byId(e){return document.getElementById(e);}
function newEl(tag){return document.createElement(tag);}
window.addEventListener('load', onDocLoaded, false);
var grid = {};
var unrevealed = 0;
var empty = -2;
var metal = -1;
var fox = 1;
var medium = 2;
var swords = 3;
var nCols = 6;
var nRows = 6;
var wantRetelling = false;
var swordFound = false;
var mediumFound = false;
var hasErrors = true;
var selected = metal;
var values = [
{name:"Unrevealed",
value: unrevealed,
color : "white"},
{name:"Empty",
value: empty,
color : "red"}
,
{name:"Metal",
value: metal,
color : "darkgrey"}
,
{name:"Fox",
value: fox,
color : "orange"}
,
{name:"Chest/Present",
value: medium,
color : "brown"}
,
{name:"Swords",
value: swords,
color : "lightblue"}
]
function onDocLoaded()
{
init()
}
function init(){
buildGrid();
recalculateGrid();
buildSelector();
}
function withinBounds(x,y)
{
if(x>=0 && y>=0 && x<=(nCols-1) && y<=(nRows-1)){
return true
}
return false;
}
function canPlace(type, tile, onlyExactMatch){
if (tile.type == type || (tile.type == unrevealed && !onlyExactMatch)){
return true;
}
else
{
return false;
}
}
function tryFitTiles(xStart,yStart){
if(!mediumFound && tryFitMedium(xStart,yStart)){
scoreMedium(xStart,yStart)
}
if(!swordFound){
if(tryFitLongSide(xStart,yStart)){
scoreLongSide(xStart,yStart);
}
if(tryFitLongTall(xStart,yStart)){
scoreLongTall(xStart,yStart);
}
}
}
function tryFitMedium(xStart,yStart)
{
return tryFitMedium(xStart,yStart,false)
}
function tryFitMedium(xStart,yStart,onlyExactMatch)
{
return canFit(xStart,yStart,1,1,medium,onlyExactMatch)
}
function scoreMedium(xStart,yStart){
addValueToTiles(xStart,yStart,1,1,4)
}
function tryFitLongSide(xStart,yStart)
{
return tryFitLongSide(xStart,yStart,false)
}
function tryFitLongSide(xStart,yStart,onlyExactMatch)
{
return canFit(xStart,yStart,2,1,swords,onlyExactMatch);
}
function scoreLongSide(xStart,yStart){
addValueToTiles(xStart,yStart,2,1,6);
}
function tryFitLongTall(xStart,yStart)
{
return tryFitLongTall(xStart,yStart,false);
}
function tryFitLongTall(xStart,yStart,onlyExactMatch)
{
return canFit(xStart,yStart,1,2,swords,onlyExactMatch);
}
function scoreLongTall(xStart,yStart){
addValueToTiles(xStart,yStart,1,2,6);
}
function canFit(xStart, yStart, xSize,ySize, type)
{
return canFit(xStart, yStart, xSize,ySize, type, false)
}
function canFit(xStart, yStart, xSize,ySize, type, onlyExactMatch)
{
var canPlaceTile = true;
if(!withinBounds((xStart+xSize),(yStart+ySize))){
return false;
}
var x, y;
for (y=0; y<=ySize; y++)
{
for (x=0; x<=xSize; x++)
{
var currentXPos = xStart + x;
var currentYPos = yStart + y;
var tile = grid[formatGridPosition(currentXPos,currentYPos)]
canPlaceTile = canPlace(type,tile,onlyExactMatch);
if(!canPlaceTile){
return false;
}
}
}
return canPlaceTile;
}
function addValueToTiles(xStart, yStart, xSize,ySize,valueToAdd)
{
var x, y;
for (y=0; y<=ySize; y++)
{
for (x=0; x<=xSize; x++)
{
var currentXPos = xStart + x;
var currentYPos = yStart + y;
var tile = grid[formatGridPosition(currentXPos,currentYPos)]
tile.value+= valueToAdd;
}
}
}
function recalculateGrid(){
clearGridValuesSection()
validateGrid();
if(!hasErrors){
var x, y;
for (y=0; y<nRows; y++)
{
for (x=0; x<nCols; x++)
{
tryFitTiles(x,y)
}
}
buildGridValuesSection();
hightlightHighestRows()
}
}
function hightlightHighestRows(){
var x, y, max;
max = 0;
for (y=0; y<nRows; y++)
{
for (x=0; x<nCols; x++)
{
var tile = grid[formatGridPosition(x,y)];
if(tile.value>max){
max = tile.value;
}
}
}
for (y=0; y<nRows; y++)
{
for (x=0; x<nCols; x++)
{
var tile = grid[formatGridPosition(x,y)];
if(tile.value==max){
byId("select"+formatGridPosition(x,y)).classList.add("bestMatch")
byId("display"+formatGridPosition(x,y)).classList.add("bestMatch")
}
}
}
}
function formatGridPosition(xpos,ypos){
return xpos + "/" + ypos;
}
function clearGridValuesSection()
{
byId('tblDebug').innerHTML = '';
}
function validateGrid()
{
clearErrors();
//Reset values
hasErrors = false;
swordFound = false;
mediumFound = false;
var swordCount = 0;
var mediumCount = 0;
var firstSword;
var firstMedium;
var x, y;
for (y=0; y<nRows; y++)
{
for (x=0; x<nCols; x++)
{
var tile = grid[formatGridPosition(x,y)];
if(tile.type == swords){
if(!firstSword){
firstSword = tile;
}
swordCount++
}else if(tile.type == medium){
if(!firstMedium){
firstMedium = tile;
}
mediumCount++
}
byId("select"+formatGridPosition(x,y)).classList.remove("bestMatch")
tile.value = 0;
}
}
if(mediumCount<4 && mediumCount > 0){
addError("If you have Found one medium tile, please fill in the rest.")
}
if(swordCount<6 && swordCount > 0){
addError("If you have Found one swords tile, please fill in the rest.")
}
if(mediumCount==4)
{
if(tryFitMedium(firstMedium.x,firstMedium.y,true)){
mediumFound = true;
}
else
{
addError("Please double check your chest/present position")
}
}
if(swordCount==6){
if(tryFitLongTall(firstSword.x,firstSword.y,true) || tryFitLongSide(firstSword.x,firstSword.y,true)){
swordFound = true;
}
else{
addError("Please double check your swords position")
}
}
if(mediumCount>4){
addError("You have too many Medium tiles")
}
if(swordCount>6){
addError("You have too many Sword tiles")
}
}
function clearErrors()
{
byId('MessageSection').innerHTML = '';
}
function addError(errorText)
{
hasErrors = true;
var error, curRow;
curRow = newEl('tr');
error = newEl('text');
error.innerHTML = '<p>' + errorText + '</p>'
curRow.classList.add("message")
curRow.appendChild(error);
byId('MessageSection').appendChild(curRow);
}
function buildSelector()
{
byId('iconSelector').innerHTML = '';
var container;
for (const val of values){
var button = newEl('button');
button.classList.add("selectorRow")
button.classList.add("selector")
button.classList.add("btn")
button.name = val.name + "selector"
button.id = val.name + "selector"
button.style.backgroundColor = val.color;
button.classList.add('addBorder');
button.addEventListener('click', selectorClick, false);
button.value = val.value;
button.text = val.name;
button.innerHTML= val.name;
if(val.value == selected){
button.classList.add('selected');
}
byId('iconSelector').appendChild(button);
}
}
function selectorClick(evt){
selected = this.value;
buildSelector();
}
function buildGridValuesSection()
{
clearGridValuesSection();
var tbl, curRow, curCell, container;
tbl = newEl('table');
var x, y;
for (y=0; y<nRows; y++)
{
curRow = newEl('tr');
tbl.appendChild(curRow);
for (x=0; x<nCols; x++)
{
container = newEl("td");
container.classList.add("square");
container.classList.add("addBorder")
container.setAttribute("id","display"+formatGridPosition(x,y))
curCell = newEl('p');
curCell.setAttribute("type", "text");
curCell.value = grid[formatGridPosition(x,y)].value;
curCell.innerHTML = grid[formatGridPosition(x,y)].value;
container.appendChild(curCell)
curRow.appendChild(container);
}
}
byId('tblDebug').appendChild(tbl);
}
function buildGrid()
{
byId('tblTgt').innerHTML = '';
grid = {};
var tbl, curRow, curCell, container;
tbl = newEl('table');
var x, y;
for (y=0; y<nRows; y++)
{
curRow = newEl('tr');
tbl.appendChild(curRow);
for (x=0; x<nCols; x++)
{
grid[formatGridPosition(x,y)] = {
x: x,
y: y,
type: unrevealed,
value: 0
}
curCell = newEl('td');
curCell.name = formatGridPosition(x,y)
curCell.id = "select" + formatGridPosition(x,y)
curCell.addEventListener('click', onGridValueChanged, false);
curCell.classList.add("square");
curCell.classList.add("btn");
//curCell.classList.add('addBorder');
curRow.appendChild(curCell);
}
}
function onGridValueChanged(evt)
{
grid[this.name].type = selected;
for (const val of values){
if(val.value == selected){
this.style.backgroundColor = val.color;
}
}
recalculateGrid();
}
byId('tblTgt').appendChild(tbl);
}
</script>
<style>
</style>
</head>
<body>
<div class="container"><h2>Faux Hollow Solver</h2></div>
<div class="container" ><table id='MessageSection'></table></div>
<hr>
<div class="container">
<div id='iconSelector' class="selectorSection"></div>
<div id='tblTgt'></div>
</div>
<hr>
<div class="container" >
<button onclick="init()" class ='btn btn-dark'>Reset</button>
</div>
<div id='tblDebug' class="hiddenSection container" ></div>
<hr>
<div id='instructions' >
<div class="container">
<h2>How to Use</h2>
</div>#
<div class="container">
<ul>
<li>Click the bar on the left to select what tile type to fill in</li>
<li>Click the grid to fill in the metal tiles</li>
<li>The tiles with the highest value (Green border) will Give you the most information</li>
<li>When you find a piece of a larger image in game, fill in the grid above with the whole image</li>
<li>If you can use your Retelling, when you find the swords Icon, reveal it</li>
<li>If you cannot use your retelling or have fully revealed the swords, then search for the Medium tile</li>
<li>If you can complete the medium tile with remaining reveals, do so</li>
<li>If you cannot finish a larger tile, search for the chance of the Bonus tile (avoid spaces you know are parts of bigger tiles)</li>
</ul>
</div>
<div class="container">
<p>By Gail Larkspur @ Omega</p>
</div>
</div>
</body>
</html>