From 05aaa5605fd3e6ea3e9976d27ebb854201b66cce Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 17 Oct 2009 22:08:10 +0000 Subject: fix missing output line --- weasel.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/weasel.c b/weasel.c index 427fc9c..d0cb58d 100644 --- a/weasel.c +++ b/weasel.c @@ -97,7 +97,7 @@ printcreature(struct creature *c) } void -printpopulation(void) +printpopulation(struct creature *best) { extern int LINES; int n; @@ -110,6 +110,7 @@ printpopulation(void) break; } printw("\n"); + printcreature(best); clrtobot(); refresh(); } @@ -175,9 +176,8 @@ intercourse() } int -success() +success(struct creature **best) { - struct creature *best = NULL; float fittest = 0; int n; @@ -186,14 +186,11 @@ success() cp = generation[n]; if (cp->fitness > fittest) { fittest = cp->fitness; - best = cp; + *best = cp; } } - assert(best); - printcreature(best); - - return best->fitness == 1.0; + return (*best)->fitness == 1.0; } void @@ -211,6 +208,7 @@ usage(void) int main(int argc, char **argv) { + struct creature *best; pthread_t dummy; int i, c, n; @@ -252,16 +250,16 @@ main(int argc, char **argv) pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - for (i = 0; !success(); i++) { + for (i = 0; !success(&best); i++) { for (n = 0; n < display; n++) pthread_create(&dummy, &attr, intercourse, NULL); - printpopulation(); + printpopulation(best); } pthread_attr_destroy(&attr); pthread_mutex_destroy(&mutexsum); - printpopulation(); + printpopulation(best); printw("\nhalted after %d generations with population of %d\n", display * i / population, population); refresh(); -- cgit v1.2.3