swarm-support
[Top][All Lists]
Advanced

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

food on unoccupied blocks


From: Stacy Oerder
Subject: food on unoccupied blocks
Date: Wed, 19 Jun 2002 16:24:36 +0200

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. Then it places food with a specific weight on every block of the
world. Now I let the bugs eat the food at a certain rate and then I
increment the food on every block at a different rate. Then I move each
bug to a new position and repeat the process. My problem comes with the
unoccupied blocks and the movement of a bug to a previously unoccupied
block. What happens when I run the program is that the bug eats properly
and moves correctly but then when you ask it to report how much food is
on the new block, which was previously unoccupied, it gives back the
value of what it's food would have been on the block that it originally
occupied. I can't seem to get the food on the unoccupied blocks to
increment as well as the bug not reporting correctly for a new block.
I'm unsure as to whether the incrementation is wrong or my bug is
actually not moving. Below I've included the code that I've written for
bug.m. Any suggestions would be greatly appreciated.

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];}
                //[food addFood: newFood X: xPos Y: yPos];}
        
        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;
}








        // If we are the reporterPrey - we check that we have eaten and
report it
        
-report {
        int pos;
        
        if (haveEaten)
                printf("There was enough food to eat at this position X
= %d Y = %d ! (SN = %d) \n", xPos, yPos, stepNumb);
        if (!haveEaten)
                printf("There is not enough food at X = %d Y = %d ! (SN
= %d) \n", xPos, yPos, stepNumb);
        printf("prey no.8");
        scanf("%d", &pos);
        return self;
}

@end

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