swarm-support
[Top][All Lists]
Advanced

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

problems (3)


From: Holger Perlt
Subject: problems (3)
Date: Mon, 03 Sep 2001 09:21:00 +0200

Hello,

first, thank you for your prompt reactions.

Now, following problems should be solved:

I have introduced two independent bug classes (Bug, Bugg). Both
act (up to now) independently on the grid. The Foodspace has been
eliminated. 
The step-method of the Bugg-class has gotten an additional parameter:
the list of the Bugs of the other class. The reason is that I want to
manipulate the list of Bugs inside the step method of the Buggs if some
conditions are fulfilled (e.g I want to drop a selected
member of the list of Bugs). Up to now I add 1 to an integer variable
(haveEaten) if 
this condition is OK. This integer is local to each Bugg.
Now the problems:

(1) The setButton-method does not work anymore. By clicking
on a bug an exception message: STATUS_ACCESS_VIOLATION is printed.
The code sequence is as follows:

 bugDisplay = [Object2dDisplay createBegin: self];
  [bugDisplay setDisplayWidget: worldRaster];
  [bugDisplay setDiscrete2dToDisplay: [modelSwarm getWorld]];
  [bugDisplay setObjectCollection: [modelSwarm getBugList]];
  [bugDisplay setDisplayMessage: M(drawSelfOn:)];   // draw method
  bugDisplay = [bugDisplay createEnd];

  buggDisplay = [Object2dDisplay createBegin: self];
  [buggDisplay setDisplayWidget: worldRaster];
  [buggDisplay setDiscrete2dToDisplay: [modelSwarm getWorld]];
  [buggDisplay setObjectCollection: [modelSwarm getBuggList]];
  [buggDisplay setDisplayMessage: M(drawSelfOn:)];   // draw method
  buggDisplay = [buggDisplay createEnd];

  // Also, tell the world raster to send mouse clicks to the
heatbugDisplay
  // this allows the user to right-click on the display to probe the
bugs.

  [worldRaster setButton: ButtonRight
               Client: bugDisplay
               Message: M(makeProbeAtX:Y:)];

(2) I want to drop a member of the Bug-List in the Bugg-step method.
Could
you give me useful hint? (my code is commented out)
To be specific:
If a Bugg would meet a Bug at its new position (newX, newY) the
corresponding
Bug sould be removed from the Bug-list.

The relevant code pieces are:

Modelswarm.m:
************

        modelActions = [ActionGroup create: self];
        [modelActions createActionForEach: buggList    message: M(step:):
bugList];
        [modelActions createActionForEach: bugList    message: M(step)];

Bugg.m:
*******

- step: (id <List>) BList
{
  int newX, newY;
  id index;
//  Bug *aBug;
  int tt;
//  int i1, i2;

  index = [BList begin: [self getZone]];

  haveEaten = 0;

  newX = xPos + [uniformIntRand getIntegerWithMin: -2 withMax: 2];
  newY = yPos + [uniformIntRand getIntegerWithMin: -2 withMax: 2];

  newX = (newX + worldXSize) % worldXSize;
  newY = (newY + worldYSize) % worldYSize;

  if ([world getObjectAtX: newX Y: newY] == nil)
    {
      [world putObject: nil atX: xPos Y: yPos];
      [world putValue: 0 atX: xPos  Y: yPos];
      xPos = newX;
      yPos = newY;
      [world putObject: self atX: newX Y: newY];
      [world putValue: 3 atX: xPos  Y: yPos];
    }
   else{
        tt = [world getValueAtX: newX Y: newY];
        if(tt == 2){
                haveEaten++;
/*              while((aBug = [index next])){
                        i1 = [aBug getX];
                        i2 = [aBug getY];
                        if(i1 == newX && i2 == newY) {
                                [BList  remove: aBug];
                                [aBug drop];
                                
                        }
                }*/
//      [world putValue: 3 atX: newX  Y: newY];
        }
        
   }

  
  [index drop];

  return self;
}


-- 
PD Dr. habil. Holger Perlt
Diplomphysiker/Geschäftsführer
Reinforcement Control GmbH
Karl-Heine-Str. 99
04229 Leipzig
Germany
Phone:  ++49 (0)341 9410370
Fax:    ++49 (0)341 9410372
http://www.reinforcement.de

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

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