So I have this function
function main()
{
//get the start text
var start_text = document.getElementById("start_text").value;
//get target text
var target_text = document.getElementById("target_text").value;
// get characters to use for modifying string
var characters = document.getElementById("characters").value;
// get the mutation rate
var mutation_rate = document.getElementById("mutation_rate").value;
// get the amount of offspring for each generation
var amount_offspring = document.getElementById("amount_offspring").value;
// send all the input into generation, to generate a generation of offspring.
// this function will return the highest scoring offspring of each generation
best_offspring = generation(start_text, characters, amount_offspring, mutation_rate, target_text, generations);
// keep looping untill the target_text is met
while(score_met == false)
{
//send the highest scoring offspring again
best_offspring = generation(best_offspring, characters, amount_offspring, mutation_rate, target_text);
// output the best offspring
document.getElementById("output_text").value = best_offspring;
// output the amount of generations
document.getElementById("generations").value = generations;
}
}
Everything works, except that it outputs the finnished string when the while loop is done.
What I want is for it to output each generations best_offspring
so that you can see the string "evolve" in real time. I tried to use the function setTimout()
like such:
while(score_met == false)
{
//send the highest scoring offspring again
best_offspring = setTimeout(generation(), 1000, best_offspring, characters, amount_offspring, mutation_rate, target_text);
document.getElementById("output_text").value = best_offspring;
document.getElementById("generations").value = generations;
}
but didnt get it to work. Any ideas?