-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
226 lines (199 loc) · 6.4 KB
/
index.html
File metadata and controls
226 lines (199 loc) · 6.4 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Easy Boggle Solitaire </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="manifest" xxhref="site.webmanifest">
<link rel="apple-touch-icon" sizes="180x180" xxhref="apple-touch-icon.png">
<!-- https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html -->
<meta name="apple-mobile-web-app-title" content="Easy Boggle Solitaire">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="format-detection" content="telephone=no">
<meta name="mobile-web-app-capable" content="yes">
<meta name="keywords" content="boggle, solitaire, puzzle, JavaScript">
<meta name="description" content="free printable boggle worksheets and boggle boards with solutions">
<script>
window.boggleVersion = '0.1';
</script>
<style>
:root {
--varOne: 10;
}
.a { transform: rotate(0deg); }
.b { transform: rotate(90deg); }
.c { transform: rotate(90deg); }
.d { transform: rotate(270deg); }
.e { transform: rotate(90deg); }
.f { transform: rotate(180deg); }
.g { transform: rotate(180deg); }
.h { transform: rotate(90deg); }
.i { transform: rotate(180deg); }
.j { transform: rotate(0deg); }
.k { transform: rotate(180deg); }
.l { transform: rotate(180deg); }
.m { transform: rotate(180deg); }
.n { transform: rotate(90deg); }
.o { transform: rotate(270deg); }
.p { transform: rotate(0deg); }
.line {
font-weight: 100;
}
.board {
margin: auto;
color: blue;
font-weight: bold;
width: 70%;
border: 1px solid black
padding: 10px;
xxfont-size: 2.5vw;
font-size: 250%;
letter-spacing: 2vw;
}
.grid {
margin-left: auto;
margin-right: auto;
margin: auto;
width: 50%;
display: grid;
xxgrid-template-columns: 3.8vw 3.8vw 3.8vw 3.8vw;
grid-template-columns: 4.8vw 4.8vw 4.8vw 4.8vw;
}
.item {
color: blue;
font-weight: bold;
xxborder: 1px solid green;
font-family: monospace;
font-size: 250%;
text-align: center;
}
.answer {
line-height: 180%;
}
.pagebreak {
page-break-after: always;
}
</style>
</head>
<body>
<!--[if IE]>
<h1> Internet Explorer is not supported </h1>
<![endif]-->
<noscript><h1> JavaScript is not enabled </h1></noscript>
<h4>Easy Boggle™ Solitaire </h4>
<button type="button" onclick="bs_randomBook()"> Random book of puzzles </button>
<br>
<h5>or</h5>
Enter a 5 letter book code to generate a specific puzzle book.
<br>
<input type="text" id="usercode" pattern="[a-z]{5}"
title="5 letter (lowercase) book code" onchange="bs_fromuserBook()"></input>
<br>
<h5>or</h5>
Enter 16 letters representing a 4x4 Boggle puzzle to solve. List letters
left to right, top to bottom.<br>
Example adqejilluketysbc<br>
Example ieearcltbtcuivrs<br>
Example toapyausizeynggy<br>
Example eyleseeaovtiitqg<br>
Example toapyausizeynggy<br>
Example nhwsifbywzehomen<br>
Example liosysdasertaaga<br>
<input type="text" id="usergame" pattern="\w{16}"
title="16 letters representing a 4x4 Boggle puzzle" onchange="bs_fromuserGame()"></input>
<script>
"use strict"
// BEGIN
class History { // a wrapper around Web Storage API
constructor() {
let keystr = localStorage.getItem(History.key); // returns string of previously gen'd books
this.prev = keystr ? keystr.split('+') : []; // Split into an array (if truthy)
}
_strRep(c) { // STRing REPresentation, intended only for internal use
return c ? c.toString() : "void";
}
isPresent(c) {
c = this._strRep(c); // expecting a string, but make damn sure
return this.prev.indexOf(c) >= 0;
}
getHist() {
return localStorage.getItem(History.key);
}
add(c) {
c = this._strRep(c); // expecting a string, but make damn sure
if (this.isPresent(c))
return null;
this.prev.unshift(c);
this.prev.length = Math.min(History.limit, this.prev.length);
return localStorage.setItem(History.key, this.prev.join('+'));
}
}
History.limit = 600;
History.key = `dont-repeat-last-${History.limit}-random-gamebooks`;
// END
function navigateToBookPage (code) {
//console.log("navigateToBookPage 5", code, window.location.href);
//console.log("navigateToBookPage 7", code, window.location.pathname);
window.location.href = `ebs.htm?code=${code}`;
}
// CAUTION: not as simple as changing c2n_letters here -- the
// constant 5 is embedded in the html also and would need to be changed too.
//
const c2n_letters = 5; // 26**5 = 11,881,376
const c2n_radix = 26; // 26 lowercase letters in the latin alphabet
function code2num(cc) {
cc = cc.slice(0, Math.min(c2n_letters, cc.length)); // assure not oversized
cc = cc.toLowerCase(cc); // assure code is entirely lowercase
//console.log(cc); // debugging
let n = 0;
for (let idx = 0; idx < cc.length; ++idx) {
n *= c2n_radix;
n += cc.charCodeAt(idx) - 97; // 97 (decimal) is the ASCII value for 'a'
}
return n;
}
function num2code(n) {
n = (n < 0) ? -n : n; // assure n is positive
n = Math.trunc(n) % c2n_radix**c2n_letters; // assure n is in range
let code = '';
let k = c2n_letters;
while (k--) {
// 97 (decimal) is the ASCII value for 'a'
code = String.fromCharCode(97+ n % c2n_radix) + code;
n = Math.trunc(n/c2n_radix);
}
return code;
}
function bs_randomBook() {
let code;
let hist = new History();
let deadman = 99; // only try so many times before giving up
while (deadman--) {
// Generate a book code, which is 5 (const c2n_letters) lowercase letter
code = num2code( Math.floor( (c2n_radix**c2n_letters) * Math.random() ));
if ( !hist.isPresent(code) )
break;
}
hist.add(code);
navigateToBookPage(code);
}
function bs_fromuserBook() {
let elem = document.getElementById("usercode");
let code = elem.value.toLowerCase().replace(/\W/g, '');
if (c2n_letters !== code.length)
return;
let hist = new History(); // Add the user-input code into the local
hist.add(code); // storage history if not there already.
navigateToBookPage(code);
}
function bs_fromuserGame() {
let elem = document.getElementById("usergame");
let game = elem.value.toLowerCase().replace(/\W/g, '');
if (16 !== game.length)
return;
window.location.href = `found.htm?game=${game}`;
}
</script>
</body>
</html>