swarm-support
[Top][All Lists]
Advanced

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

Re: FoodSpace Problems


From: Paul E Johnson
Subject: Re: FoodSpace Problems
Date: Tue, 07 May 2002 14:35:39 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020326

I don't know why you are trying to do this with an *.scm file, but I can warn you that many people get the format of the *.scm file incorrect and then it does not work. Numerical values have to have letters after them representing variable types. Its pretty fussy about formatting too.

Heres a clip from one example showing an integer, a double, and a boolean in an scm file.

 #:lastIdenticalCall 200
 #:parochialism 0.500000D0
 #:consistentAdjustment #t

I've got some comments below.

Stacy Oerder wrote:
Hi

Thanks for previous advice with regards to the values stored in
foodspace, after taking into account that foodspace should have
integers, my problem diminshed but didn't solve totally. Included below
are a copy of my foodspace.h and foodspace.m files. Using my variables
declared in my prey.scm file my foodspace correctly reads in my original
food value but is still not reading in the size of my world and I'm
having a problem with my -addFood method as it doesn't seem to register
my foodvalue at the xy position which is initially the original food and
then changes each time step as food is added and eaten. If anyone has
any suggestions I'd greatly appreciate it, I am a new user and some of
the use of the language may be incorrect. I have tried to follow
existing examples in the writing of my code to date.

//FoodSpace.h

#import <space/Discrete2d.h>
#import <space.h>

typedef int FoodValue;

@interface FoodSpace : Discrete2d {
}
int x, y;
int worldXSize, worldYSize;
int foodHere;
int extraFood;
int origFood;
int newFood;

-setOriginalFood: (int) origFood;
-addFood: (FoodValue)newFood X: (int) x Y: (int) y;

@end


//FoodSpace.m
#import "FoodSpace.h"
#import <random.h>

@implementation FoodSpace

-setOriginalFood: (int) origFood {
        for (x = 0; x<worldXSize; x++)
                for (y = 0; y<worldYSize; y++)
                        [self putValue: origFood atX: x Y: y];
        return self;
        }
You have a problem here, I don't understand even why this compiles. If you have an instance variable origFood, the compiler should yell at you about using that same name as the input variable in the setOriginalFood method. You either don't need to input that variable or you don't need the IVAR. IF it is an IVAR and the value is defined, all you need is:

-setOriginalFood {
        for (x = 0; x<worldXSize; x++)
                for (y = 0; y<worldYSize; y++)
[self putValue: origFood atX: x Y: y];
        return self;
        }

-addFood: (FoodValue) newFood X: (int) x Y: (int) y {
        foodHere = [self getValueAtX: x Y: y];
        newFood = foodHere + newFood;
        [self putValue: newFood atX: x Y: y];
        
        return self;
}

Something looks funny about this last one. I don't know why you create the
type "FoodValue".

I don't think you need instance variables "newFood", and I'm not sure about extraFood.

Assuming you want to add an integer amount "newFood" to the existing food, should it not be:


-addFood: (int) newFood X: (int) x Y: (int) y {
        int newTotal;
        foodHere = [self getValueAtX: x Y: y];
        newTotal = foodHere + newFood;
        [self putValue: newTotal atX: x Y: y];
        
        return self;
 }

--
Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (785) 864-9086
Lawrence, Kansas 66045                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]