diff --git a/wordle.htm b/wordle.htm index 9c9ef96..f05c61a 100644 --- a/wordle.htm +++ b/wordle.htm @@ -57,13 +57,13 @@ var valid_words = null; })() +var inited = false const cur_status = [0, 0, 0, 0, 0] var cur_guess = null var num_guess = 0 var chosen_words = []; (() => { - inited = false window.addEventListener('load', () => { document.getElementById('init').addEventListener('click', e => { if (!inited) { @@ -94,6 +94,10 @@ var chosen_words = []; }) document.getElementById('find').addEventListener('click', e => { + if (!inited) { + status("please initialize the solver first") + return + } if (words_len(valid_words) == 1) { status("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 => { + if (!inited) { + status("please initialize the solver first") + return + } if (cur_guess != null) { var nodes = [] const cur_word = document.getElementById('cur-word') @@ -194,6 +202,26 @@ var chosen_words = []; 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") + }) }) })() @@ -217,6 +245,7 @@ var chosen_words = [];