swarm-support
[Top][All Lists]
Advanced

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

Using the Array type


From: Holger Perlt
Subject: Using the Array type
Date: Tue, 28 Aug 2001 08:11:56 +0200

Hello,

I try to modify the bug (ObserverBug) step by step.

(a) I introduce two independent species of bugs (Elben, Orks)
The Elben are put into the usual List. The Orks are defined
as elements of an Array - in order to have an easy access to
specific species.
The compilation goes through - at run time I get an
STATUS_ACCESS_VIOLATION
error message.
The main new codes are inside ModelSwarm.m:

buildObjects:

(the 200 as setCount parameter is arbitrary - I wanted to be sure that
no index range error could occur!)

bugListOrks = [Array create:  [self getZone] setCount: 200];

  for(ii =0; ii < 20; ii++){
  for (y = worldYSize - 8; y < worldYSize + 8; y++)
    for (x = worldXSize - 8; x < worldXSize + 8; x++)
      if ([world getObjectAtX: x Y: y] == nil)
        {
          aOrk = [Ork createBegin: self];
          [aOrk setWorld: world Food: food];
          aOrk = [aOrk createEnd];
          [world putValue: 3  atX: x Y: y];
          [aOrk setX: x Y: y];
          [aOrk setEat: 0 Y: 0];
          [bugListOrks atOffset : ii put: aOrk];

        }
        else
          [bugListOrks atOffset : ii put: nil];
  }

buildActions:


modelActions = [ActionGroup create: self];
  [modelActions createActionForEach: bugListElben    message: M(stepp:)
: bugListOrks];
  [modelActions createActionForEach: bugListOrks    message: M(step)];



and in Elben.m:

(these lines have up to now no deep meaning)

- stepp : (id <Array>) OrkList
{
  int newX, newY;
  int tt;


  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: 2  atX: newX Y: newY];
    }
   else{
        tt = [world getValueAtX: newX Y: newY];
        if (tt == 3){
                [world putValue: 1  atX: newX Y: newY]; 


   }
    
  return self;
}


I think it is best to attach the code

Thank you,

Holger


-- 
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

Attachment: tolkien.tar.gz
Description: GNU Zip compressed data


reply via email to

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