swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help request from a SWARM newbie


From: Fabio Mascelloni
Subject: Help request from a SWARM newbie
Date: Wed, 27 Jan 1999 15:52:05 +0100

I'd like to modify simpleSwarmBug2 in this way:

Each Bug has a certain amount of strenght (a float value initially set to 0) that increases of ,let's say, 0.1 every time it eats.
Then, when a Bug  wants to move to anather location (-step) that is already occupied by another Bug, it checks if its own strenght is higher than that of its "enemy" :if it's so,
it destroys it (in my mind,that would mean to make the bugList remove the defeated Bug), otherwise goes on.
Here are the parts of source I've modified:
In "Bug.h":

added inst.variables id bugEnemy and float strenght;
added inst.var id myList; (the List whose the bug is part)
added method -getStrenght (returns Bug's strenght)
added method -setList:(id) aList (sent by bugList as a message to set itself
                                                      as the bug list)

In "Bug.m",I added the following lines to the -step method:
.....
//Check that no other bug is at the new site

     if ((enemy=[world getObjectAtX: newX Y: newY])==nil)
                  {

            [world putObject:nil atX:xPos Y:yPos];
            [world putObject:self atX:newX Y: newY];
            xPos=newX;
            yPos=newY;

                  }
       else if (strenght >= [enemyBug getStrenght]) //space is not free and  
                                                                                //you're stronger
         {
            [myList remove:enemyBug];
         }
 
         if ([foodSpace getValueAtX: xPos Y: yPos]==1)
        {
          [foodSpace putValue:0 AtX: xPos Y: yPos];
          strenght+=0.1;
         } .........

In "ModelSwarm.m" I added the following bold line:
.....
aBug = [Bug createBegin: self];
          [aBug setWorld: world Food: food];
          [aBug setList:bugList];
          aBug = [aBug createEnd];
.......

The rest of code is left unchanged.
Because it's only three days since I begun to study SWARM,I couldn't pretend my varation would have worked,infact the runtime system complains:Exception:STATUS_ACCES_VIOLATION
What was my error?
Finally a question on leaving unspecified the return value of a method (making it to return the default type id) even when it hasn't to return any value:it's a matter of  style or is there something behind that?

Thank you in advance for your advice.
_______________________________________________________________
Fabio Mascelloni.
Dept. of Computer Science - University of Pisa,Italy
e-mail: address@hidden


reply via email to

[Prev in Thread] Current Thread [Next in Thread]