5-001 // Sugarscape in Swarm. Copyright © 1997 Nelson Minar
5-002 // This program is distributed without any warranty; without even the
5-003 // implied warranty of merchantability or fitness for a particular purpose.
5-004 // See file LICENSE for details and terms of copying.
5-005 
5-006 // The SugarSpace is the object that represents the environment of the model.
5-007 // Its main component is the amount of sugar in the world.
5-008 // It also enforces dynamics on the sugar space (growing new sugar) and
5-009 // keeps track of where all the agents are.
5-010 
5-011 #import <objectbase/SwarmObject.h>
5-012 #import <space.h>
5-013 
5-014 @class SugarAgent;
5-015 
5-016 // A SugarValue is a measurement of how much sugar is at the world.
5-017 // We define a new type here, but it's basically just an integer
5-018 typedef int SugarValue;
5-019 
5-020 // Here is the SugarSpace object itself. It inherits very little behaviour,
5-021 // but contains various objects to store properties of the world.
5-022 @interface SugarSpace: SwarmObject
5-023 {
5-024   unsigned int xsize, ysize;				  // grid size
5-025   
5-026   id <Discrete2d> sugar;			  // sugar at each spot
5-027   int sugarGrowRate;				  // alpha, from the book
5-028   
5-029   const char *maxSugarDataFile;			  // filename for max sugar
5-030   id <Discrete2d> maxSugar;			  // max sugar at each spot
5-031   SugarValue globalMaxSugar;			  // absolute maximum for space
5-032   
5-033   id <Grid2d> agentGrid;			  // agent positions
5-034 }
5-035 
5-036 // Use this method at object creation - set the size of the world.
5-037 - setSizeX: (int)x Y: (int)y;
5-038 - (int)getSizeX;
5-039 - (int)getSizeY;
5-040 // Also set the maximum sugar datafile
5-041 - setMaxSugarDataFile: (const char *)s;
5-042 
5-043 // Dynamics; add more sugar to the world. This is rule G_alpha of the book.
5-044 // there are also methods here to change the grow rate.
5-045 - updateSugar;
5-046 - setSugarGrowRate: (int)r;
5-047 - (int)getSugarGrowRate;
5-048 
5-049 // This code handles the main property of a SugarSpace: how much sugar
5-050 // there is at each spot in the world, and taking that sugar.
5-051 - (SugarValue)getSugarAtX: (int)x Y: (int)y;
5-052 - (SugarValue)takeSugarAtX: (int)x Y: (int)y;
5-053 - (id <Discrete2d>)getSugarValues;
5-054 
5-055 // Read out the maximum value of sugar from the space
5-056 - (SugarValue)getGlobalMaxSugar;
5-057 
5-058 // This code handles the position of all the agents in the sugarspace.
5-059 // Look for agents in the space, add, move, and remove them.
5-060 - (SugarAgent *)getAgentAtX: (int)x Y: (int)y;
5-061 - addAgent: (SugarAgent *)agent atX: (int)x Y: (int)y;
5-062 - removeAgent: (SugarAgent *)agent;
5-063 - moveAgent: (SugarAgent *)agent toX: (int)x Y: (int)y;
5-064 
5-065 // Get the array of all the agents in the space.
5-066 - (id <Grid2d>)getAgentGrid;
5-067 
5-068 // coordinate normalization. This handles coordinates out of range by
5-069 // wrapping them around.
5-070 - (int)xnorm: (int)x;
5-071 - (int)ynorm: (int)y;
5-072 
5-072  @end
