aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-17 22:08:10 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-17 22:08:10 +0000
commit05aaa5605fd3e6ea3e9976d27ebb854201b66cce (patch)
treeb8502260c8e1ec2fa67ddc77719673425d9a4cd6
parent842779f5c6cfd8e5e0ee302d358adf0a540d764a (diff)
fix missing output line
-rw-r--r--weasel.c20
1 files 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();