on_input = {
const masked_input = adventure_input.split("\n").slice(-1);
const adventure_response = game.advance(masked_input).join(" ");
const score = parseInt(
(/(\d+)/.exec(
adventure
.makeState(JSON.parse(JSON.stringify(game)))
.advance("score")
.find((x) => x.startsWith("SCORE"))
) || ["0", "0"])[1]
);
viewof game_history.value.push({
input: adventure_input,
response: adventure_response,
score,
turn: (viewof game_history.value.slice(-1)[0]?.turn || 0) + 1
});
viewof game_history.dispatchEvent(new Event("input"));
mutable output =
mutable output + "<br>> " + adventure_input + "<br>" + adventure_response;
if (game.state == "init_yesno") {
viewof adventure_input[0].value = "no";
viewof adventure_input.dispatchEvent(new Event("submit"));
} else {
viewof adventure_input.value = "";
}
return `${adventure_input} -> ${adventure_response}`;
}