aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2009-10-03 23:13:32 +0000
committerDimitri Sokolyuk <demon@dim13.org>2009-10-03 23:13:32 +0000
commit4bad1ea4a92d330db5ce5e563315de398a63ea21 (patch)
tree34634836878b51d2238e494469ad617b7bd18382
parent6869d4cfe87be85d461c490ea87a8447e72475f3 (diff)
replace TAILQ with SLIST
-rw-r--r--weasel.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/weasel.c b/weasel.c
index f6b38ff..ef86a16 100644
--- a/weasel.c
+++ b/weasel.c
@@ -45,13 +45,13 @@ const char alphabet[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEEFGHIJKLMNOPQRST
const char *aim;
-TAILQ_HEAD(creatures, creature) generation;
+SLIST_HEAD(creatures, creature) generation;
struct creature {
char *genom;
int length;
float fitness;
int locked;
- TAILQ_ENTRY(creature) link;
+ SLIST_ENTRY(creature) link;
} *cp;
char
@@ -78,7 +78,7 @@ initpopulation(int length, int number)
{
int i;
- TAILQ_INIT(&generation);
+ SLIST_INIT(&generation);
while (number-- > 0) {
cp = malloc(sizeof(struct creature));
@@ -91,7 +91,7 @@ initpopulation(int length, int number)
cp->length = length;
cp->fitness = calculatefitness(cp->genom, cp->length);
cp->locked = 0;
- TAILQ_INSERT_HEAD(&generation, cp, link);
+ SLIST_INSERT_HEAD(&generation, cp, link);
}
}
@@ -105,7 +105,7 @@ void
printpopulation(int maximal)
{
printw("%1.3f\t%s\n\n", 1.0, aim);
- TAILQ_FOREACH(cp, &generation, link) {
+ SLIST_FOREACH(cp, &generation, link) {
printcreature(cp);
if (maximal-- <= 0)
break;
@@ -118,9 +118,9 @@ pickrandom(int population)
{
int n = arc4random() % population;
- cp = TAILQ_FIRST(&generation);
+ cp = SLIST_FIRST(&generation);
while (n-- > 0 && cp)
- cp = TAILQ_NEXT(cp, link);
+ cp = SLIST_NEXT(cp, link);
if (cp->locked)
cp = pickrandom(population);
@@ -173,7 +173,7 @@ success()
float fittest = 0;
/* find best */
- TAILQ_FOREACH(cp, &generation, link)
+ SLIST_FOREACH(cp, &generation, link)
if (cp->fitness > fittest) {
fittest = cp->fitness;
best = cp;