/* * (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 edu.brook.ascape.model.*;import edu.brook.ascape.rule.*;import edu.brook.ascape.util.*;/** * A rule causing the agent to reproduce with as many neighbors * as possible in random order. * * @author Miles Parker * @version 1.0 **/public class PromiscuousReprod extends Rule {    public PromiscuousReprod() {        super("Promiscuous Reproduction");    }    /**     * Reproduce with as many agents as possible.     * @param agent the reproducing agent     */    public void execute(Agent agent) {        Cell[] neighbors = ((CellOccupant) agent).getNeighborsOnHost();        //pick a random series from the set of series that match the number of neighbors        //(Assumes von Neumann neighborhood, otherwise creates error)        int[] series = Utility.uniqueSeries[neighbors.length][randomToLimit(Utility.uniqueSeries[neighbors.length].length)];        for (int i = 0; i < series.length; i++) {             if (!((SexualAgent) agent).isFertile()) {                break;            }            SexualAgent mate = (SexualAgent) neighbors[series[i] - 1];            if ((((SexualAgent) agent).isFemale() != mate.isFemale()) && (mate.isFertile())) {                if ((((CellOccupant) agent).getHostCell().isNeighborAvailable()) || (mate.getHostCell().isNeighborAvailable())) {                    SexualAgent child = (SexualAgent) ((SexualAgent) agent).clone();                    ((ScapeVector) agent.getScape()).addAgent(child);                    child.initialize();                    //Leave initially assigned cell                    child.leave();                    child.setSugar(((SexualAgent) agent).takeSugar(((SexualAgent) agent).getContributionToChild()));                    child.setSugar(mate.takeSugar(mate.getContributionToChild()));                    child.setAge(0);                                        if (randomIs()) {                        child.setVision(((SexualAgent) agent).getVision());                    }                    else {                        child.setVision(mate.getVision());                    }                                        if (randomIs()) {                        child.setSugarMetabolism(((SexualAgent) agent).getSugarMetabolism());                    }                    else {                        child.setSugarMetabolism(mate.getSugarMetabolism());                    }                                        if ((((CellOccupant) agent).getHostCell().isNeighborAvailable())) {                        child.moveTo(((CellOccupant) agent).getHostCell().findRandomAvailableNeighbor());                    }                    else {                        child.moveTo(mate.getHostCell().findRandomAvailableNeighbor());                    }                }            }        }    }        public boolean isRandomExecution() {        return false;    }            public boolean isCauseRemoval() {        return false;    }    }
