# Patrick Coleman # Comp Sys Res - 6th period - 2007-08 # Sugarscape - location class Location #x-position, y-position, capacity for sugar, amount of sugar, growback rate, #true if an agent is in this location, true if quanitity is less than capacity attr_accessor :posX, :posY, :sugarcapac, :sugarquant, :growback, :hasAgent, :changed #Initialize all variables def initialize (posX,posY,capac, growback=1) @posX = posX @posY = posY @sugarcapac = capac @sugarquant = capac @growback = growback @changed = false #At first, no agent is here @hasAgent = -1 end #Sets the amount of sugar to zero, returns amount of sugar harvested, and sets changed to true def harvest #Quits if no sugar otherwise sets change to true return 0 if @sugarquant == 0 temp = @sugarquant @sugarquant = 0 @changed = true temp end #Increments the amount of sugar by the growback rate if the location is not at full capacity, #otherwise sets changed to false def grow s = (getStep/100)%6 if @posY > 25 and s > 0 and s < 4 #and false if @sugarquant != 0 @sugarquant -= 1 @changed = true else @changed = false end elsif @posY < 25 and s > 4 #and false if @sugarquant != 0 @sugarquant -= 1 @changed = true else @changed = false end elsif @sugarquant < @sugarcapac @sugarquant += growback @changed = true else @changed = false end end end