X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Flink%2FC%2Fagents%2Fc_wash.c;h=557464e5c498618d90fd81b23ee4a46ebd45e74b;hb=refs%2Fheads%2Fmaster;hp=9ca4a413965031cad4ab35562abb5b06f79b5a47;hpb=4f032479507641dacc772624c4a6b56a664fb249;p=progcomp10.git diff --git a/src/link/C/agents/c_wash.c b/src/link/C/agents/c_wash.c index 9ca4a41..557464e 100644 --- a/src/link/C/agents/c_wash.c +++ b/src/link/C/agents/c_wash.c @@ -1,5 +1,5 @@ /* - * c_frechie.c + * c_wash.c * c-link-lib * * Created by Daniel Axtens on 22/04/10. @@ -32,10 +32,12 @@ gospel on the number of agents you're going to see. */ #define NUMBEROFAGENTSGUESS 100 +typedef char agentName[MAXAGENTNAMELEN]; + /* data for each instance of my agent */ typedef struct { /* The name of the n-th foe who has beaten us */ - char (*defeatingFoes)[MAXFOENAMELEN]; + agentName * defeatingFoes; /* The length of the array, and how far we are along it */ size_t foesLen; @@ -50,7 +52,7 @@ int haveLostTo( wash_data * me, char * foeName ) { /* check every foe we know to have defeated us */ for (foe=0; foefoesCount; foe++) { - if (strncmp( me->defeatingFoes[foe], foeName, MAXFOENAMELEN) == 0) { + if (strncmp( me->defeatingFoes[foe], foeName, MAXAGENTNAMELEN) == 0) { //debugmsg( "%d\thaveLostTo( %s ) -> Yes\n", me, foeName ); return 1; } @@ -64,7 +66,7 @@ int haveLostTo( wash_data * me, char * foeName ) { void * Initialise( char * myName ) { wash_data * me = malloc( sizeof( wash_data ) ); - me->defeatingFoes = calloc( NUMBEROFAGENTSGUESS, sizeof( MAXFOENAMELEN*sizeof(char) ) ); + me->defeatingFoes = calloc( NUMBEROFAGENTSGUESS, sizeof( agentName ) ); me->foesLen = NUMBEROFAGENTSGUESS; me->foesCount = 0; @@ -149,7 +151,7 @@ void Results( void * this, char * foeName, int isInstigatedByYou, /* if we've already lost the foe, don't store again */ for (foe=0; foefoesCount; foe++) { - if (strncmp( me->defeatingFoes[foe], foeName, MAXFOENAMELEN ) == 0) { + if (strncmp( me->defeatingFoes[foe], foeName, MAXAGENTNAMELEN ) == 0) { /* we've found it! */ return; } @@ -159,11 +161,11 @@ void Results( void * this, char * foeName, int isInstigatedByYou, if (me->foesCount==me->foesLen) { /* double the array size. This should error check, but doesn't */ me->defeatingFoes = realloc( me->defeatingFoes, - me->foesLen*2*sizeof( MAXFOENAMELEN*sizeof(char) ) ); + me->foesLen*2*sizeof( agentName ) ); me->foesLen *= 2; } - strncpy( me->defeatingFoes[me->foesCount], foeName, MAXFOENAMELEN ); + strncpy( me->defeatingFoes[me->foesCount], foeName, MAXAGENTNAMELEN ); me->foesCount++; return; @@ -174,4 +176,4 @@ void Cleanup( void * this ) { wash_data * me = (wash_data *) this; free(me->defeatingFoes); free(me); -} \ No newline at end of file +}