Implement a back function
This commit is contained in:
parent
ad3f7f0323
commit
37ade8158d
31
wordle.htm
31
wordle.htm
|
@ -57,13 +57,13 @@ var valid_words = null;
|
||||||
|
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
var inited = false
|
||||||
const cur_status = [0, 0, 0, 0, 0]
|
const cur_status = [0, 0, 0, 0, 0]
|
||||||
var cur_guess = null
|
var cur_guess = null
|
||||||
var num_guess = 0
|
var num_guess = 0
|
||||||
var chosen_words = [];
|
var chosen_words = [];
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
inited = false
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
document.getElementById('init').addEventListener('click', e => {
|
document.getElementById('init').addEventListener('click', e => {
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
|
@ -94,6 +94,10 @@ var chosen_words = [];
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('find').addEventListener('click', e => {
|
document.getElementById('find').addEventListener('click', e => {
|
||||||
|
if (!inited) {
|
||||||
|
status("please initialize the solver first")
|
||||||
|
return
|
||||||
|
}
|
||||||
if (words_len(valid_words) == 1) {
|
if (words_len(valid_words) == 1) {
|
||||||
status("the word is " + words[valid_words[0]])
|
status("the word is " + words[valid_words[0]])
|
||||||
log("the word is " + words[valid_words[0]])
|
log("the word is " + words[valid_words[0]])
|
||||||
|
@ -165,6 +169,10 @@ var chosen_words = [];
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('confirm').addEventListener('click', e => {
|
document.getElementById('confirm').addEventListener('click', e => {
|
||||||
|
if (!inited) {
|
||||||
|
status("please initialize the solver first")
|
||||||
|
return
|
||||||
|
}
|
||||||
if (cur_guess != null) {
|
if (cur_guess != null) {
|
||||||
var nodes = []
|
var nodes = []
|
||||||
const cur_word = document.getElementById('cur-word')
|
const cur_word = document.getElementById('cur-word')
|
||||||
|
@ -194,6 +202,26 @@ var chosen_words = [];
|
||||||
cur_guess = null
|
cur_guess = null
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
document.getElementById('back').addEventListener('click', e => {
|
||||||
|
if (chosen_words.length == 0) return
|
||||||
|
if (!inited) {
|
||||||
|
status("please initialize the solver first")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
chosen_words.pop()
|
||||||
|
const history = document.getElementById('history')
|
||||||
|
history.removeChild(history.lastChild)
|
||||||
|
|
||||||
|
// replay the game up to this point
|
||||||
|
valid_words = gen_all_words_list()
|
||||||
|
for (var i = 0; i < chosen_words.length; i++) {
|
||||||
|
invalidate_words(valid_words, chosen_words[i][0], undump_match(chosen_words[i][1]))
|
||||||
|
}
|
||||||
|
const num_valid = words_len(valid_words)
|
||||||
|
log("removed last added word, " + num_valid + " words left")
|
||||||
|
status("removed last added word, " + num_valid + " words left")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
</script>
|
</script>
|
||||||
|
@ -217,6 +245,7 @@ var chosen_words = [];
|
||||||
</form>
|
</form>
|
||||||
<div id=status>loading words...</div>
|
<div id=status>loading words...</div>
|
||||||
log:
|
log:
|
||||||
|
<!-- TODO show a sorted list of all the valid words or all the best words to guess with -->
|
||||||
<div id=log class=log></div>
|
<div id=log class=log></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue