Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
273 lines (228 loc) · 7.75 KB
/
Copy pathindex.html
File metadata and controls
273 lines (228 loc) · 7.75 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
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
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<script src=EN.js></script>
<script src=FR.js></script>
<div id=pagemenu>
<h1>Boggle</h1>
<div id=menu>
<button id=en>ENGLISH</button>
<button id=fr>FRANÇAIS</button>
<div id=day class=mono></div>
</div>
</div>
<div id=pageboard class=hidden>
<div class=x>×</div>
<h1>Boggle board</h1>
<br>
<center>
<p><button id=bogglego>GO</button>
</center>
<br>
<div id=boggleboard></div>
<div id=boggleboardsolution></div>
</div>
<div id=pagesolver class=hidden>
<div class=x>×</div>
<h1>Boggle solver</h1>
<center>
<p><textarea id=boggleinput maxlength=16></textarea>
<p><button id=boggleok>OK</button>
</center>
<div id=bogglesolution></div>
</div>
<script>
checkboggle = (word, grid) => {
if(word.length < 3) return false;
for(var i = 0; i < 16; i++){
if(grid[i] == word[0]){
tmp = grid.slice(); // copy grid
tmp[i] = "?"; // remove current letter
if(subcheckboggle(word.slice(1), i, tmp)){
return true
}
}
}
return false;
}
subcheckboggle = (word, index, grid) => {
if(word.length == 0) return true;
var link = bogglelinks[index];
for(var i = 0; i < link.length; i++){
if(link[i][1] == word[0] && grid[link[i][0]] != "?"){
tmp = grid.slice(); // copy grid
tmp[link[i][0]] = "?"; // remove current letter
if(subcheckboggle(word.slice(1), link[i][0], tmp)){
return true
}
}
}
return false;
}
// Choose language / init games
words = [];
lang = (dico, langId) => {
words = dico;
pagemenu.innerHTML = `<h1>Boggle</h1><div id=menu><p><button id=boardbutton>BOARD</button> <button id=solverbutton>SOLVER</button>`;
boardbutton. => { game(0); }
solverbutton. => { game(1); }
}
en. => lang(EN, 0);
fr. => lang(FR, 1);
// Choose game
game = game => {
pagemenu.classList.add("hidden");
// board
if(game == 0){
pageboard.classList.remove("hidden");
}
// solver
if(game == 1){
pagesolver.classList.remove("hidden");
}
}
// board
bogglego. => {
// Minutes since 01-01-1970 (UTC)
minutes = Math.floor(Date.now() / (1000 * 60));
//console.log(minutes);
// all letters
boggleletters = "AAEEGNAOOTTWCIMOTUDISTTYEIOSSTDELRVYEHRTVWACHOPSHIMNUQEEINSUAFFKPSHLNNRZEEGHNWDEILRXELRTTYABBJOO";
// letters of the day
boggletodayletters = [];
for(i = 0; i < 16; i++){
boggletodayletters.push(boggleletters[(minutes * i) % boggleletters.length]);
boggleletters = boggleletters.replace(boggletodayletters[boggletodayletters.length-1],'');
}
boggleboard.innerHTML = boggletodayletters.join(" ").replace(/(. . . .)/g,"$1<br>");
}
// solver
boggleok. => {
var grid = boggleinput.value;
// words of the day
bogglewords = [];
bogglelinks = [];
for(i = 0; i < 16; i++){
bogglelinks[i] = [];
// top left
if((i / 4) >= 1 && (i % 4) >= 1){
bogglelinks[i].push([i-5, grid[i-5]]);
}
// top
if((i / 4) >= 1){
bogglelinks[i].push([i-4, grid[i-4]]);
}
// top right
if((i / 4) >= 1 && (i % 4) < 3){
bogglelinks[i].push([i-3, grid[i-3]]);
}
// left
if((i % 4) >= 1){
bogglelinks[i].push([i-1, grid[i-1]]);
}
// right
if((i % 4) < 3){
bogglelinks[i].push([i+1, grid[i+1]]);
}
// bottom left
if((i / 4) < 3 && (i % 4) >= 1){
bogglelinks[i].push([i+3, grid[i+3]]);
}
// bottom
if((i / 4) < 3){
bogglelinks[i].push([i+4, grid[i+4]]);
}
// bottom right
if((i / 4) < 3 && (i % 4) < 3){
bogglelinks[i].push([i+5, grid[i+5]]);
}
}
for(i = 0; i < words.length; i++){
if(words[i] && checkboggle(words[i], grid)){
bogglewords.push(words[i]);
}
}
bogglesolution.innerHTML = bogglewords.join(" ");
}
/*
// Boggle
// input
boggleinput. => {
if(key.key == "Enter"){
boggleok.click();
}
}
// OK
bogglewordsfound = [];
boggleok. => {
currentword = boggleinput.value;
if(bogglewords.includes(currentword) && !bogglewordsfound.includes(currentword)){
// score
boggleresult.innerHTML += currentword + " ";
bogglewordsfound.push(currentword);
bogglescore.innerHTML = bogglewordsfound.length;
}
boggleinput.value = "";
if(bogglewordsfound.length == bogglewords.length){
boggleinput.value = "Congrats!";
boggleinput.disabled = true;
}
}
*/
// Inputs in uppercase / trimmed
= (e) => {
e.srcElement.value = e.srcElement.value.toUpperCase().trim();
}
// Close game
=> {
if(e.target.classList.contains("x")){
pagemenu.classList.remove("hidden");
pageboard.classList.add("hidden");
pagesolver.classList.add("hidden");
}
}
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Fira+Mono:wght@400;500;700');
.mono {
font-family: "Fira Mono", monospace;
font-weight: 400;
font-style: normal;
}
* {
margin: 0;
padding: 0;
border: 0;
box-sizing: border-box;
}
html { min-height: 100vh; background: #fff; }
body { width: 100%; max-width: 490px; margin: auto; background: linear-gradient(#def,#fff); padding: 20px; min-height: 100vh; font: 20px calibri, arial, sans-serif; position: relative; }
h1 { text-align: center; font-size: 60px; line-height: 60px; color: #037; margin: 0; user-select: none; }
h2 { text-align: center; font-size: 15px; color: #222; margin: 10px; user-select: none; }
h3 { text-align: center; font-size: 34px; color: #222; margin: 10px; user-select: none; }
button { padding: 10px; border: 2px solid; background: #eee; font-size: 20px; font-weight: bold; }
input { padding: 10px; border: 2px solid; background: #fff; font-size: 20px; font-weight: bold; width: 200px; }
#menu button { width: 200px; display: block; margin: 20px auto 0; user-select: none; }
#day { position: absolute; bottom: 0; right: 0; margin: 20px; font-size: 12px; }
.x { position: absolute; top: 0; right: 0; margin: 0 20px; font-size: 50px; cursor: pointer; user-select: none; }
#wordleresult { font-size: 30px; text-align: center }
#motigmaresult { font-size: 25px; font-weight: bold; text-align: center; font-family: "Fira Mono", monospace; letter-spacing: 2px; }
#spellingbeeresult { font-size: 25px; font-weight: bold; text-align: center; }
#spellingbeetotal { text-align: center; }
#boggleresult { font-size: 25px; font-weight: bold; text-align: center; }
#boggletotal { text-align: center; }
#motigmaresult p { width: 150px; display: inline-block; }
#boggleboard { font-size: 50px; font-weight: bold; text-align: center; font-family: "Fira Mono", monospace; letter-spacing: 0px; margin: 20px 0; }
#maxiwordboard { font-size: 30px; font-weight: bold; text-align: center; font-family: "Fira Mono", monospace; letter-spacing: 0px; margin: 20px 0; }
.maxiwordinputs { font-size: 20px; font-weight: bold; margin: 20px 0; columns: 2; vertical-align: top; }
.maxiwordinputs input { padding: 5px; width: 160px; }
.maxiwordinputs p { margin: 0 0 5px; }
#maxiwordtotal { text-align: center; }
p { margin: 10px 0 }
.green, .orange, .no { display: inline-block; width: 40px; height: 40px; margin: 0 7px 0 0; padding: 5px; line-height: 30px; font-weight: bold; }
.green { background: #7e7 }
.orange { background: #fb5 }
.hidden { display: none }
#pagemenu a { text-decoration: none; text-align: center; display: block; width: 100%; position: absolute; bottom: 10px; left: 0; font-size: 24px; }
#boggleinput { width: 155px; height: 175px; font-size: 50px; line-height: 40px; font-weight: bold; font-family: "Fira Mono", monospace; letter-spacing: 2px; resize: none; border: 2px solid; display: block; margin: 20px auto; }
#bogglesolution { font-size: 20px; font-weight: bold }
</style>