aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2010-02-09 19:31:17 +0000
committerDimitri Sokolyuk <demon@dim13.org>2010-02-09 19:31:17 +0000
commitaca4d820bc36c445263d3a993a73d1c7fc81f250 (patch)
treea3d82ea8cc0c09ad823416f30ade7e3fa8cb674c
parent57f4f1cbedd680bf16e6f01063cdda7ea55d93e2 (diff)
typedef
-rw-r--r--weasel.c25
1 files 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;