forked from powerlanguage/guess-my-word
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguess-generator.html
122 lines (103 loc) · 4.11 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
<!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" onchange="changeDifficulty()">
<option value="normal">normal</option>
<option value="hard">hard</option>
</select>
</h1>
<a class="bigger-target" href="./README.html">about</a>
</header>
<pre>
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 | sed -e 's/^.* //' > /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 | sed -e 's/^.* //' > /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><h3>new</h3><textarea 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/vue@2.6.11"></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;
const existingExcludesList = {
normal: normalListExclude,
hard: hardListExclude,
};
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 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>