Implement the reset

This commit is contained in:
Kelvin Ly 2023-05-11 14:00:49 -04:00
parent 61e87095b4
commit ad3f7f0323
1 changed files with 35 additions and 18 deletions

View File

@ -55,11 +55,12 @@ var valid_words = null;
}) })
req.send() req.send()
})(); })()
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 = [];
(() => { (() => {
inited = false 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 => { document.getElementById('find').addEventListener('click', e => {
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]])
return
} }
const [idx, entropy] = calc_best_word(valid_words) const [idx, entropy] = calc_best_word(valid_words)
status("best word is " + words[idx] + " , " + entropy) status("best word is " + words[idx] + " , " + entropy)
@ -162,6 +187,7 @@ var num_guess = 0;
} }
} }
if (guess_idx == -1) return if (guess_idx == -1) return
chosen_words.push([guess_idx, [...cur_status]])
invalidate_words(valid_words, guess_idx, undump_match(cur_status)) invalidate_words(valid_words, guess_idx, undump_match(cur_status))
log("guessed " + cur_guess + " " + words_len(valid_words) + " words left") log("guessed " + cur_guess + " " + words_len(valid_words) + " words left")
status("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> </head>
<body> <body>
<div class="history" id="history"> <div class="history" id="history"></div>
<!--
<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 id="cur-word"></div> <div id="cur-word"></div>
<form> <form>
<p> <p>
<input id="guess" minlength=5 maxlength=5 size=5></input> <input id="guess" minlength=5 maxlength=5 size=5></input>
</p> </p>
<p> <p>
<input type=button id="init" value="Init search"></input> <input type=button id="init" value="Initialize"></input>
<input type=button id="clear" value="Reset game"></input> <input type=button id="reset" value="Reset game"></input>
<input type=button id="submit" value="Submit word"></input> <input type=button id="submit" value="Submit word"></input>
<input type=button id="confirm" value="Confirm 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> <input type=button id="find" value="Find best"></input>
</p> </p>
</form> </form>
<div id=status></div> <div id=status>loading words...</div>
log: log:
<div id=log class=log></div> <div id=log class=log></div>
</body> </body>