swarm-modeling
[Top][All Lists]
Advanced

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

[Swarm-Modelling] world getObjectAt and Others


From: Georg A.
Subject: [Swarm-Modelling] world getObjectAt and Others
Date: Sun, 15 Jun 2003 15:25:44 +0200

On Tuesday, Jun 3, 2003, at 16:26 Europe/Berlin, Paul E. Johnson wrote:

I can't help unless you tell what exactly you did why/how it did not work.


I got ants running frome source to nest, two different sizes and either carrying something or not. this are attribute which I can set via methods // setBigAnt setCarryItem
if this ants meet each other the following happens
1: if a big ant with food meets a small ant or another big ant without food, nothing happens, the ant walks further towards the nest 2: if a big unloaded ant meets a small loaded ant, it takes the food and returns to the nest, the small one walks back towards the source.
genarrly loaden ants walk towards the nest, unloaden towards the source
what I implemented is this:

- step
// the part of walking from source to nest and backwards
// and the conditions for exchanging food and changing places
{
    int newX, newY;


    if(([self isBigAnt] == YES) & ([self getCarryItem] == YES))
    {
        if ((xPos + 1)< 100)
        {
            newX = xPos + 1;
        }
        else if ((xPos + 1) == 100)
        {
            newX = xPos - 1;
            [self setNewCarryItem];
        }
    }

    else if (([self isBigAnt] == YES) & ([self getCarryItem] == NO))
    {
        if ((xPos - 1) > 0)
        {
            newX = xPos - 1;
        }
        else if ((xPos - 1 ) == 0)
        {
            newX = xPos + 1;
            [self setposCarryItem];
        }

    }


    else if (([self isBigAnt] == NO) & ([self getCarryItem] == NO))
    {
        if ((xPos - 1) > 0)
        {
            newX = xPos - 1;
        }
        else if ((xPos - 1) == 0)
        {
            newX = xPos + 1;
            [self setposCarryItem];
        }

    }

    else if (([self isBigAnt] == NO) & ([self getCarryItem] == YES))
    {
        if ((xPos + 1) < 101)
        {
            newX = xPos + 1;
            [self setNewCarryItem];
        }
        else if ((xPos + 1) == 100)
        {
            newX = xPos - 1;
            [self setNewCarryItem];
        }

    }

    newY = yPos + [uniformIntRand getIntegerWithMin: -1 withMax: 1];

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

    // Check that no other ant is at the new site.

    if ([world getObjectAtX: newX Y: newY] == nil)
    {
        [world putObject: nil atX: xPos Y: yPos];
        xPos = newX;
        yPos = newY;
        [world putObject: self atX: newX Y: newY];
    }

  return self;
}

but how can catch the event of the meeting of two ants so that I can
implement the exchange of the food and the change in the walking direction?

thanks a lot

--



Georg Apitz

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WALS Project
Executive Programmer

Max Planck Institute for Evolutionary Anthropology
Deutscher Platz 6
04103 Leipzig
Germany
Phone: +49 (0) 341 3550 - 314
Telefax: +49 (0)341 3550 - 333

address@hidden
www.eva.mpg.de
www.ge-org.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



reply via email to

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