Attempt at fixing memory mess.
[progcomp10.git] / src / link / C / c_link.c
index 39dda6b..524697d 100755 (executable)
@@ -57,29 +57,26 @@ int main( int argc, char * argv[] ) {
        srand( time( NULL ) );\r
        \r
        char command[MAXCOMMANDLEN];\r
-       char foeName[MAXFOENAMELEN];\r
+       char foeName[MAXAGENTNAMELEN];\r
        char attItem[MAXITEMLEN], defItem[MAXITEMLEN], bluffItem[MAXITEMLEN];\r
        char didYouInstigate[MAXBOOLLEN];\r
        char winner[MAXRESULTLEN];\r
+       char uuid[MAXAGENTNAMELEN];  \r
        int pointChange;\r
-       void *thisInstance;\r
+       void *thisInstance = NULL;\r
 \r
        ATTACKTYPE attack;\r
        ITEMTYPE defence;\r
        \r
-       /* generate a random id for this bot. Hopefully it's unique\r
-          I can't use the UUID, because python doesn't pass it to me! */\r
-       me = rand();\r
-       \r
-       // TODO: Get the UUID passed by python\r
-       // Currently, just pass an empty string to the initialise function\r
-       thisInstance = Initialise( "" );\r
-       \r
        scanf( "%s", command );\r
        \r
        while (strcasecmp("BYE",command) != 0) {\r
                \r
-               if (strcasecmp("ATTACK", command) == 0) {\r
+               if (strcasecmp("HI", command) == 0) {\r
+                       scanf( "%s", uuid );\r
+                       thisInstance = Initialise( uuid );\r
+                       \r
+               } else if (strcasecmp("ATTACK", command) == 0) {\r
                        scanf( "%s", foeName );\r
                        attack = Attack( thisInstance, foeName );\r
                        printf("ATTACKING %s %s\n", ITEMNAMES[attack.realAttack], ITEMNAMES[attack.promisedAttack]);\r
@@ -104,7 +101,8 @@ int main( int argc, char * argv[] ) {
                scanf( "%s", command );\r
        }\r
        \r
-       Cleanup(thisInstance);\r
+       if( thisInstance )\r
+               Cleanup(thisInstance);\r
        \r
        return 0;\r
 }\r

UCC git Repository :: git.ucc.asn.au