-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathguess-generator.html
204 lines (172 loc) · 7.18 KB
/
guess-generator.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
<!doctype html>
<html lang="en">
<head>
<title>GMW - new words</title>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./index.css"/>
</head>
<body>
<header>
<h1>
<a href="./" class="home">Guess my word</a>
<select id="difficulty-changer">
<option value="normal">normal</option>
<option value="hard">hard</option>
</select>
</h1>
<a class="bigger-target" href="./README.html">about</a>
</header>
<h2>New just use random repeats way</h2>
<p>
This breaks the existing list into 3 chunks of 526 (and skips the first three as there's no normal words there). For each chunk, take it, randomize it, then put it back on the end of the list.
</p>
<p>
Once you're done with that, put a checkmark ✔️ out front so can use the next one next time.
</p>
<pre>
// in JS console
# List 1 ✔️
copy("'" + possibleWords.normal.slice(3,529).join("',\n'") + "',");
copy("'" + possibleWords.hard.slice(3,529).join("',\n'") + "',")
# List 2 ✔️
copy("'" + possibleWords.normal.slice(529,1055).join("',\n'") + "',");
copy("'" + possibleWords.hard.slice(529,1055).join("',\n'") + "',");
# List 3 👈 **next time**
copy("'" + possibleWords.normal.slice(1055,1581).join("',\n'") + "',");
copy("'" + possibleWords.hard.slice(1055,1581).join("',\n'") + "',");
</pre>
<hr>
<h3>Appendix - old manual way</h3>
Look at top some 1000 most guessed words
<pre style="max-width: 100%; white-space: break-spaces;">
cat backupLeaderboards/*normal.csv | grep -v timeInMilliSeconds | sed -e 's/^.*,"//' -e 's/".*$//' | sed -e 's/,[a-z]*$//' | tr "," \n | grep -E "...." | sort | uniq -c | sort -rn | head -n 7000 | tail -n 1000 | sed -e 's/^.* //' | sort > /tmp/guessed-normal-words
cat backupLeaderboards/*hard.csv | grep -v timeInMilliSeconds | sed -e 's/^.*,"//' -e 's/".*$//' | sed -e 's/,[a-z]*$//' | tr "," \n | grep -E "...." | sort | uniq -c | sort -rn | head -n 8000 | tail -n 1000 | sed -e 's/^.* //' | sort > /tmp/guessed-hard-words
</pre>
<button id="analyze">Analyze new words</button>
<div style="display: flex">
<div><h3>accepted</h3><textarea id="accepted" rows="30"></textarea></div>
<div style="flex-grow: 1;"><h3>new <small><button onclick='reduceNewWords()'>reduce</button></small></h3>
<textarea style="width: 100%" id="new" rows="30"></textarea>
</div>
<div><h3>exclude</h3><textarea id="exclude" rows="30"></textarea></div>
</div>
<script src="https://d2t3dun0il9ood.cloudfront.net/dictionary.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="index.js"></script>
<script src="normal-word-exclude-list.js"></script>
<script src="hard-word-exclude-list.js"></script>
<script>
getElement('analyze').onclick = validateNewWords;
getElement('new').onkeyup = moveWord;
const existingExcludesList = {
normal: normalListExclude.split('\n').filter(w => w),
hard: hardListExclude.split('\n').filter(w => w),
};
const newExcludesList = {
normal: [],
hard: [],
};
const acceptedNewWords = {
normal: [],
hard: [],
}
getInvalidReason.guesses = [];
function validateNewWords(e) {
let newWords = getWordsFromElement('new');
const difficulty = getElement('difficulty-changer').value;
newExcludesList[difficulty] = getWordsFromElement('exclude');
acceptedNewWords[difficulty] = getWordsFromElement('accepted');
const previousWords = possibleWords.normal
.concat(possibleWords.hard) // hard and normal words should not overlap
.concat(acceptedNewWords[difficulty]);
const wordsToExclude = new Set(
previousWords
.concat(existingExcludesList[difficulty])
.concat(newExcludesList[difficulty])
);
const actualNewWords = [];
const warnWords = [];
const POTENTIAL_BAD_ENDINGS = /(ing|ed|ly)$/;
newWords.sort().forEach(word => {
if (wordsToExclude.has(word)) {
console.log(`${word} is in previous guesses, accepted guesses, or old/new exclude list`);
return;
}
if (getInvalidReason(word)) {
console.log(`${word} is somehow not in dictionary`);
return;
}
const likeOldWord = previousWords.find(oldWord => oldWord.startsWith(word) || word.startsWith(oldWord));
if (likeOldWord) {
actualNewWords.push(`${word} is a lot like ${likeOldWord}`);
return;
}
const badEndingMatch = word.match(POTENTIAL_BAD_ENDINGS);
if (badEndingMatch) {
actualNewWords.push(`${word} ends with "${badEndingMatch[0]}"`);
return;
}
actualNewWords.push(word);
});
setWordsInElement(actualNewWords, 'new');
}
function moveWord(e) {
const {key} = e;
if (key !== 'ArrowLeft' && key !== 'ArrowRight') return;
const textarea = getElement('new');
const cursorPosition = textarea.selectionStart;
console.log('cursorPosition', cursorPosition);
const lineText = getLineText();
const word = lineText.replace(/ .+/, '');
if (!word) return;
if (key === 'ArrowLeft') {
// textarea.selectionStart = cursorPosition + 1;
getElement('accepted').value += word + '\n';
} else {
getElement('exclude').value += word + '\n';
// textarea.selectionStart = cursorPosition - 1;
// textarea.selectionEnd = cursorPosition - 1;
}
textarea.value = textarea.value.replace(lineText + '\n', '');
textarea.selectionStart = 2;
textarea.selectionEnd = textarea.selectionStart;
function getLineText() {
const fullValue = textarea.value;
// console.log(`char @ cursor is ${fullValue[cursorPosition]}`);
let start = cursorPosition;
while (start > 0 && fullValue[start - 1] !== '\n') {
start -= 1;
}
let end = cursorPosition;
while (end < (fullValue.length) && fullValue[end] !== '\n') {
end += 1;
}
const fullLine = fullValue.slice(start, end);
const movedBetweenLines = fullLine.includes('\n');
if (movedBetweenLines) return '';
return fullLine;
}
}
function reduceNewWords() {
const newWords = getWordsFromElement('new');
const reducedNewWords = newWords.filter((word, i) =>
Math.floor(i / 5) % 2 === 0 // take first 5, drop next 5, take next 5, etc.
);
setWordsInElement(reducedNewWords, 'new');
}
function getWordsFromElement(id) {
return getElement(id).value
.split('\n')
.filter(w => w.trim()); // exclude anything empty
}
function setWordsInElement(words, id) {
return getElement(id).value = words.join('\n');
}
function getElement(id) {
return document.querySelector(`#${id}`);
}
</script>
<!-- Uncomment to run tests in browser -->
<!-- <script src="./tests.js"></script> -->
</body>
</html>