Multi-Agent Simulation Based on Swarm 53
TABLE 3.1: Tutorial contents.
simpleCBug Procedural programming
simpleObjCBug 1 Object-oriented programming
2 Bug and FoodSpace interaction
simpleSwarmBug 1 Object r e sp onsible for the simulation
Schedule
2 Multiple Bugs
3 Parameter settings with files
simpleObserverBug 1 Display on the 2-dimensional plane
2 Probe to acce ss the object
simpleExperBug Multiple models
Hierarchical schedules
Graphical display
FoodSpace, and is the subclass of Discrete2dImp1. The following lines, inside
FoodSpace.java,
public FoodSpace(Zone aZone,int x,int y){
super(aZone,x,y);
}
contain a constructor, in which super executes the constructor of
Discrete2dImp1.
FoodSpace inherits the internal variables and methods fro m
Discrete2dImp1. It makes the retention and retrieval of values of the two-
dimensional spac e possible. The newly added method by FoodSpace is only
seedFoodWithProb. Note that the getSizeX, getDoubleWithMin$withMax
methods used in this definition are inherited from Discrete2dImp1. In
seedFoodWithProb, at each point in the FoodSpace a random number be-
tween 0 and 1 is g e nerated. If the value of the position is les s than seedProb,
it changes the value to 1 (that is, putValue$atX$Y(1,x,y)). This is to
achieve the bait at concentration of seedProb. In this program, the variable
(foodSpace) of FoodSpace is defined as an internal variable of Bug. It ho lds
the world in which it moves. In the part below the method “step,” if the new
location has bait, it eats the bait (substitutes the va lue of 0) and displays that
position.
if (foodSpace.getValueAtX$Y(xPos,yPos) == 1){
foodSpace.putValue$atX$Y(0,xPos,yPos);
System.out.println("I found food at X = " + xPos + " Y = "
+ yPos +"!");
}