From aca4d820bc36c445263d3a993a73d1c7fc81f250 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 9 Feb 2010 19:31:17 +0000 Subject: typedef --- weasel.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/weasel.c b/weasel.c index 5483ea3..712b618 100644 --- a/weasel.c +++ b/weasel.c @@ -47,6 +47,8 @@ int alphalen; char *aim; +typedef struct creature Creature; + struct creature { char *genom; int length; @@ -69,6 +71,7 @@ ncpu(void) return n; } + char rndchar() { @@ -93,11 +96,11 @@ initpopulation(int length) { int i, n; - generation = calloc(population, sizeof(struct creature *)); + generation = calloc(population, sizeof(Creature *)); assert(generation); for (n = 0; n < population; n++) { - cp = malloc(sizeof(struct creature)); + cp = malloc(sizeof(Creature)); assert(cp); cp->genom = malloc(length + 1); assert(cp->genom); @@ -112,7 +115,7 @@ initpopulation(int length) } void -printcreature(struct creature *c) +printcreature(Creature *c) { int attr = A_NORMAL; @@ -127,7 +130,7 @@ printcreature(struct creature *c) } void -printpopulation(struct creature *best) +printpopulation(Creature *best) { extern int LINES; int n; @@ -147,7 +150,7 @@ printpopulation(struct creature *best) refresh(); } -struct creature * +Creature * pickrandom() { int hasone = 0; @@ -166,8 +169,8 @@ pickrandom() int cmp(const void *u, const void *v) { - struct creature * const *a = u; - struct creature * const *b = v; + Creature * const *a = u; + Creature * const *b = v; if ((*a)->fitness < (*b)->fitness) return 1; @@ -180,7 +183,7 @@ cmp(const void *u, const void *v) void * intercourse() { - struct creature *c[3]; + Creature *c[3]; int i; pthread_mutex_lock(&mutexsum); @@ -189,7 +192,7 @@ intercourse() assert(c[i]); } pthread_mutex_unlock(&mutexsum); - qsort(c, 3, sizeof(struct creature *), cmp); + qsort(c, 3, sizeof(Creature *), cmp); for (i = 0; i < c[2]->length; i++) { if (random() % mutationrate) @@ -212,7 +215,7 @@ intercourse() } int -success(struct creature **best) +success(Creature **best) { float fittest = 0; int n; @@ -266,7 +269,7 @@ switchcase(char *s, int *uflag) int main(int argc, char **argv) { - struct creature *best; + Creature *best; pthread_t *threads; int i, c, n, nthreads; int display = 1; -- cgit v1.2.3