swarm-modeling
[Top][All Lists]
Advanced

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

[Swarm-Modelling] Re: world getObjectAt and Others


From: Georg A.
Subject: [Swarm-Modelling] Re: world getObjectAt and Others
Date: Mon, 16 Jun 2003 22:34:52 +0200

On Monday, Jun 16, 2003, at 01:38 Europe/Berlin, Norberto Eiji Nawa wrote:


Hope it helps (But I think I'm missing your point...)

Eiji

Eiji,

I guess you know my point but I screw something up, I tried your hint with the following code, but
if I run it there are objects placed on top of each other ...
what a I doing wrong?
I commented the first lines to let you know what I mean

// Check that no other ant is at the new site.
    newY = yPos + [uniformIntRand getIntegerWithMin: -1 withMax: 1];
    newY = (newY + worldYSize) % worldYSize;
    newX = (newX + worldXSize) % worldXSize;

    antcheck = [world getObjectAtX: newX Y: newY];
//this loop is for the case my line has empty spaces there the ants can move to
   if (antcheck == nil)
   {
       [world putObject: nil atX: xPos Y: yPos];
       xPos = newX;
       yPos = newY;
       [world putObject: self atX: newX Y: newY];
   }

//
   else if (antcheck != nil)
   {
       BOOL bigAnt = [antcheck isBigAnt];
       BOOL carryItem = [antcheck getCarryItem];

// if an ant is big and carries something, it walks straight towards the nest // if it happens to meet somebody empty, they change places, but I think I have a mistake // in case somebody with a carryItem is in front, I implemented it in doing nothing, but in fact both
// of the ants should walk further towards the nest, how can I do this?
       if (BigAndCarry == YES)
       {
if ((bigAnt == NO) & (carryItem == YES)) // small with carry item, nothing happens, guess that is wrong, they need to move
           {
               [world putObject: self atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: antcheck atX: newX Y: newY];
           }
else if ((bigAnt == NO) & (carryItem == NO)) // empty one, change places
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
           }
else if ((bigAnt == YES) & (carryItem == NO)) // empty one, change places
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
           }
       }
       if (BigNothing == YES)
       {
           if ((bigAnt == NO) & (carryItem == YES))
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
               [self setposCarryItem];
               [antcheck setNewCarryItem];
           }
           else if ((bigAnt == NO) & (carryItem == NO))
           {
               [world putObject: self atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: antcheck atX: newX Y: newY];
           }
           else if ((bigAnt == YES) & (carryItem == YES))
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
           }

       }
       if (SmallCarry == YES)
       {
           if ((bigAnt == YES) & (carryItem == YES))
           {
               [world putObject: self atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: antcheck atX: newX Y: newY];
           }
           else if ((bigAnt == NO) & (carryItem == NO))
           {
               [world putObject: self atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: antcheck atX: newX Y: newY];
           }
           else if ((bigAnt == YES) & (carryItem == NO))
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
               [self setNewCarryItem];
               [antcheck setNewCarryItem];
           }

       }
       if (SmallNothing == YES)
       {
           if ((bigAnt == NO) & (carryItem == YES))
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
           }
           else if ((bigAnt == YES) & (carryItem == NO))
           {
               [world putObject: self atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: antcheck atX: newX Y: newY];
           }
           else if ((bigAnt == YES) & (carryItem == YES))
           {
               [world putObject: antcheck atX: xPos Y: yPos];
               xPos = newX;
               yPos = newY;
               [world putObject: self atX: newX Y: newY];
           }


       }
   }

--
########################################
address@hidden
www.ge-org.com

Unser Leben ist das, wozu es unser Denken macht.
########################################



reply via email to

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