/* * (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 * Alan Lockard * alockard@gmu.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.*;import java.applet.*;import edu.brook.ascape.model.*;import edu.brook.ascape.rule.*;import edu.brook.ascape.util.*;import edu.brook.ascape.view.*;/** * Extends GAS_Base so that the scape can include spice as well as sugar */public class GAS_SpiceBase extends GAS_Base {    protected float spiceMoundness = .008f; // was .004    protected int minSpiceMetabolism = 1;  // was 1    protected int maxSpiceMetabolism = 3; // was 4    protected int minInitialSpice = 0;    protected int maxInitialSpice = 30;    public void createScape() {        setPrototypeAgent(new ScapeVector());	    sugarscape = (ScapeGraph) Geometry.PERIODIC_2D_VON_NEUMANN.newScape(new SpiceCell(), new Coordinate2DDiscrete(50, 50));        SpiceAgent agent = new SpiceAgent();        agent.setHostScape(sugarscape);	    agents = new ScapeVector();	    agents.setPrototypeAgent(agent);	    agents.setExtent(new Coordinate1DDiscrete(400));        sugarscape.setExecutionOrder(Scape.RULE_ORDER);        sugarscape.setCellsRequestUpdates(true);        addAgent(sugarscape);        addAgent(agents);    }    public void initialize() {	    super.initialize();	    setSugarMoundness(.008f);	    setMinSugarMetabolism(1); // was 1	    setMaxSugarMetabolism(3); // was 4	    setMaxVision(10);	    setMinVision(10);  // eliminates variation in vision    }    /**     * Returns the topology parameter for spice peaks     */    public float getSpiceMoundness() {	    return spiceMoundness;    }    /**     * Sets the topology parameter for spice peaks     */    public void setSpiceMoundness (float moundness) {        spiceMoundness = moundness;    }    /**     * Returns the minimum spice metabolism that an agent may be given on initialization.     * Model parameter.     */    public int getMinSpiceMetabolism() {        return minSpiceMetabolism;    }        /**     * Sets the minimum spice metabolism that an agent may be given on initialization.     * Model parameter.     */    public void setMinSpiceMetabolism(int _minMetabolism) {        minSpiceMetabolism = _minMetabolism;    }        /**     * Returns the maximum spice metabolism that an agent may be given on initialization.     * Model parameter.     */    public int getMaxSpiceMetabolism() {        return maxSpiceMetabolism;    }        /**     * Returns the minimum spice that an agent may be given on initialization.     * Model parameter.     */    public int getMinInitialSpice() {        return minInitialSpice;    }        /**     * Sets the minimum spice that an agent may be given on initialization.     * Model parameter.     */    public void setMinInitialSpice(int _minInitialSpice) {        minInitialSpice = _minInitialSpice;    }        /**     * Returns the maximum spice that an agent may be given on initialization.     * Model parameter.     */    public int getMaxInitialSpice() {        return maxInitialSpice;    }        /**     * Sets the maximum spice that an agent may be given on initialization.     * Model parameter.     */    public void setMaxInitialSugar(int _maxInitialSpice) {        maxInitialSpice = _maxInitialSpice;    }        /**     * Sets the maximum Spice metabolism that an agent may be given on initialization.     * Model parameter.     */    public void setMaxSpiceMetabolism(int _maxMetabolism) {        maxSpiceMetabolism = _maxMetabolism;    }    public void createViews() {        super.createViews();	    final ColorFeatureGradiated colorCellForSugar = new ColorFeatureGradiated("Sugar");	    colorCellForSugar.setDataPoint(new UnitIntervalDataPoint() {            public double getValue(Object object) {                return ((double) (double) ((SpiceCell) object).getSugar().getQuantity() / (double) SpiceCell.MAX_SUGAR);            }	    });	    colorCellForSugar.setMaximumColor(Color.yellow);  	    final ColorFeatureGradiated colorCellForSpice = new ColorFeatureGradiated("Spice");	    colorCellForSpice.setDataPoint(new UnitIntervalDataPoint() {                public double getValue(Object object) {                    return ((double) (double) ((SpiceCell) object).getSpice().getQuantity() / (double) SpiceCell.MAX_SPICE);                }	    });	    colorCellForSpice.setMaximumColor(Color.pink);		    ColorFeature colorSugarOrSpice = new ColorFeatureConcrete("colorSugarOrSpice") {		        public Color getColor(Object object) {		            if (((SpiceCell) object).getSpice().getQuantity() > ((SpiceCell) object).getSugar().getQuantity()) {				        return colorCellForSpice.getColor(object);				    }				    else {				        return colorCellForSugar.getColor(object);				    }		        }		    };	    sugarView.setCellColorFeature(colorSugarOrSpice);    }}
