/* * (c) 1998-2000 The Brookings Institution, All Rights Reserved * * Permission to use this software and its documentation for non-commercial * purposes and without fee is hereby granted, provided this copyright statement * is included. Please contact us for permission for redistribution and other uses. *  * BROOKINGS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,  * OR NON-INFRINGEMENT. BROOKINGS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY * LICENSEE AS A RESULT OF USING THIS SOFTWARE OR ITS DERIVATIVES. * * _Sugarscape_ * See _Growing Artificial Societies: Social Science from the Ground Up_ * Brookings Institution Press, The MIT Press * Joshua Epstein * jepstein@brook.edu * Robert Axtell * raxtell@brook.edu * * Miles Parker * mparker@brook.edu * http://www.brook.edu/es/dynamics/models/ascape * The Brookings Institution * Washington, D.C. */package edu.brook.sugarscape;import java.lang.*;import java.awt.Color;import edu.brook.ascape.model.*;import edu.brook.ascape.rule.*;import edu.brook.ascape.util.*;public class SugarSeasonalGrowBackRule extends Rule {            private float epsilon = 0.125f;            private int seasonLength = 50;        public SugarSeasonalGrowBackRule() {        super("Sugar Grow Back Seasonally");    }        public SugarSeasonalGrowBackRule(float epsilon, int SeasonLength) {        super("Sugar Grow Back Seasonally");        this.epsilon = epsilon;        this.seasonLength = seasonLength;    }        public void execute(Agent agent) {        int iter = agent.getScape().getIteration();        if ((((float) iter / ((float) seasonLength * 2)) - (iter / (seasonLength * 2))) > .5) {            //Summer            if (((Coordinate2DDiscrete) ((Cell) agent).getCoordinate()).getYValue() < 25) {                ((SugarCell) agent).sugarGrowBack1();            }            else {                ((SugarCell) agent).sugarGrowBackEpsilon(epsilon);            }        }        else {            //Winter            if (((Coordinate2DDiscrete) ((Cell) agent).getCoordinate()).getYValue() < 25) {                ((SugarCell) agent).sugarGrowBackEpsilon(epsilon);            }            else {                ((SugarCell) agent).sugarGrowBack1();            }        }    }        /**     * Returns the rate at which sugar grows back in the winter.     * Model parameter.     */    public float getWinterSugarGrowbackRate() {        return epsilon;    }        /**     * Sets the rate at which sugar grows back in the winter.     * Model parameter.     */    public void setWinterSugarGrowbackRate(float epsilon) {        this.epsilon = epsilon;    }        /**     * Returns the rate at which sugar grows back in the winter.     * Model parameter.     */    public int getSeasonLength() {        return seasonLength;    }        /**     * Sets the rate at which sugar grows back in the winter.     * Model parameter.     */    public void setSeasonLength(int seasonLength) {        this.seasonLength = seasonLength;    }}
