swarm-support
[Top][All Lists]
Advanced

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

Re: food on unoccupied blocks


From: Paul E Johnson
Subject: Re: food on unoccupied blocks
Date: Wed, 19 Jun 2002 09:34:01 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020606

Stacy Oerder wrote:
I've built a swarm model that does the following, it creates a world
with a specific size and then places a few bugs on the world at random
sights.
 ^^^^^^^^
  sites :)

Thanks
Stacy Oerder

//Prey.m
#import "Prey.h"
#import <random.h>
#import <space/Discrete2d.h>

@implementation Prey


-setWorld: w Food: f {
        world = w;
        food = f;
        return self;
        
}

-createEnd {
        [super createEnd];
        worldXSize = [world getSizeX];
        worldYSize = [world getSizeY];
        return self;
}

-setX: (int) x Y: (int) y {
        xPos = x;
        yPos = y;
        stepNumb = 0;
        return self;

}


-step {

        int pos;
        
        haveEaten = 0;
        origFood = 1000;
        amountEaten = 350;
        extraFood = 100;
        stepNumb++;
        
foodHere = [food getValueAtX: xPos Y: yPos]; printf("foodhere - prey %d \n", foodHere);
        if ((foodHere) >= amountEaten) {
                printf("There is enough food to eat \n");
                amountLeft = foodHere - amountEaten;
                haveEaten =1;}
                else
                        {
                        amountLeft = foodHere;
                        }
                printf("The food left - prey %d \n", amountLeft);
        
        //bug moves sequentially through world  
        newX = xPos + 1;        
        newY = yPos;
        if (newX >= worldXSize) {
                newY = yPos + 1;
                }


        newX = (newX + worldXSize) % worldXSize;
        newY = (newY + worldYSize) % worldYSize;
        
        // Check that no other prey 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];}
It appears to me that, right here, you need:
                 foodHere = [food getValueAtX: newY Y: newY];
In order to tell the agent what its food condition is at the new spot.


                //[food addFood: newFood X: xPos Y: yPos];}
        
The following does not work because your agent is on the cell, so it never is nil, and the food level never gets updated.

I don't think you should be having the agents cause the world to update.
I think, instead, there should be a separate action, triggered from the Model, which causes each cell in the world to adjust its food level. That way all cells get updated however you want.


        if ([world getObjectAtX: newX Y: newY] == nil) {
                foodHere = foodHere + extraFood;
                printf("The food here - prey/unoccupied %d \n",
foodHere);
                scanf("%d", &pos);
                }
                                
                else
                        {foodHere = amountLeft + extraFood;
                        printf("The food here - prey/occupied %d \n",
foodHere);
                        scanf("%d", &pos);
                        }
                        
                [food putValue: foodHere atX: xPos Y: yPos];
foodHere = [food getValueAtX: xPos Y: yPos]; printf("foodhere - prey %d \n", foodHere);

        if ((foodHere) <= amountEaten) {
                printf("There is not enough food to be eaten \n");
        }
printf("prey 1 \n");
                scanf("%d", &pos);        

        
        return self;
}



--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ku.edu/~pauljohn
1541 Lilac Lane, Rm 504
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66044-3177           FAX: (785) 864-5700


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