From ad3f7f0323ee2bd5783ad93ad0fd1f20b3279f36 Mon Sep 17 00:00:00 2001 From: Kelvin Ly <kelvin.ly1618@gmail.com> Date: Thu, 11 May 2023 14:00:49 -0400 Subject: [PATCH] Implement the reset --- wordle.htm | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/wordle.htm b/wordle.htm index 62a4f11..9c9ef96 100644 --- a/wordle.htm +++ b/wordle.htm @@ -55,11 +55,12 @@ var valid_words = null; }) req.send() -})(); +})() -const cur_status = [0, 0, 0, 0, 0]; -var cur_guess = null; -var num_guess = 0; +const cur_status = [0, 0, 0, 0, 0] +var cur_guess = null +var num_guess = 0 +var chosen_words = []; (() => { inited = false @@ -70,9 +71,33 @@ var num_guess = 0; } }) + document.getElementById('reset').addEventListener('click', e => { + cur_guess = null + num_guess = 0 + chosen_words.length = 0 + valid_words = gen_all_words_list() + + const history_elem = document.getElementById('history') + while (history_elem.firstChild) { + history_elem.removeChild(history_elem.lastChild) + } + + const cur_word_elem = document.getElementById('cur-word') + while (cur_word_elem.firstChild) { + cur_word_elem.removeChild(cur_word_elem.lastChild) + } + + const log_elem = document.getElementById('log') + while (log_elem.firstChild) { + log_elem.removeChild(log_elem.lastChild) + } + }) + document.getElementById('find').addEventListener('click', e => { if (words_len(valid_words) == 1) { status("the word is " + words[valid_words[0]]) + log("the word is " + words[valid_words[0]]) + return } const [idx, entropy] = calc_best_word(valid_words) status("best word is " + words[idx] + " , " + entropy) @@ -162,6 +187,7 @@ var num_guess = 0; } } if (guess_idx == -1) return + chosen_words.push([guess_idx, [...cur_status]]) invalidate_words(valid_words, guess_idx, undump_match(cur_status)) log("guessed " + cur_guess + " " + words_len(valid_words) + " words left") status("guessed " + cur_guess + " " + words_len(valid_words) + " words left") @@ -174,31 +200,22 @@ var num_guess = 0; </head> <body> - <div class="history" id="history"> - <!-- - <div> - <span class="letter match">W</span> - <span class="letter exists">E</span> - <span class="letter notincluded">A</span> - <span>R</span> - <span>Y</span> - </div> - --> - </div> + <div class="history" id="history"></div> <div id="cur-word"></div> <form> <p> <input id="guess" minlength=5 maxlength=5 size=5></input> </p> <p> - <input type=button id="init" value="Init search"></input> - <input type=button id="clear" value="Reset game"></input> + <input type=button id="init" value="Initialize"></input> + <input type=button id="reset" value="Reset game"></input> <input type=button id="submit" value="Submit word"></input> <input type=button id="confirm" value="Confirm word"></input> + <input type=button id="back" value="Back"></input> <input type=button id="find" value="Find best"></input> </p> </form> - <div id=status></div> + <div id=status>loading words...</div> log: <div id=log class=log></div> </body>