//predator-prey model
PredatorPreyModel.java
PredatorPreySpace.java
PredatorPreyAgent.java
Predator.java

Prey.java



package predatorprey;

import java.awt.Color;

import uchicago.src.sim.gui.SimGraphics;

public class Prey extends PredatorPreyAgent
{
    /**
     * @param minLifeSpan
     * @param maxLifeSpan
     */
    public Prey(int minLifeSpan, int maxLifeSpan, int maximumEnergy, int energyGain, int energyUse, double mateProbability, int open)
    {
        super(minLifeSpan, maxLifeSpan, maximumEnergy, energyGain, energyUse, mateProbability, open);
        setS("prey");
        //setEnergyUse(getEnergyPreyUseEachTick()); 
    }

    public void report()
    {
        System.out.println(getMale()+ getID() + " at " + getX() + ", " + getY() + " has "
                + getFood() + " grass" + " and " + getStepsToLive()
                + " steps to live.");
    }

    public void draw(SimGraphics G)
    {
   //     if (getStepsToLive() > 10)
            G.drawFastRoundRect(Color.black);
    //    else
    //        G.drawFastRoundRect(Color.blue);
    }

    /**
     * @param newX
     * @param newY
     */
    private void compatibleMatch(int newX, int newY)
    {
        Prey sa =  getPredatorPreySpace().getPreyAgentAt(newX, newY);
        if (sa != null)
        { 
            if (sa.getMale()!=getMale()&&(sa.getStepsToLive() < 0.8*sa.getInitialLifeTime())
                    &&(getStepsToLive() < 0.8*getInitialLifeTime())&& Math.random() < getMateProbability()&& getEnergy()>getEnergyLimit()/2)
            {
                mate(); 
                setEnergy((int)((getEnergy()-1)/2));
            }
        }
    }

    public void escape()
{
    
}
}
//