/** * Agent.java * * --Copyright notice-- * * Copyright (c) School of Geography, University of Leeds. * http://www.geog.leeds.ac.uk/ * This software is licensed under 'The Artistic License' which can be found at * the Open Source Initiative website at... * http://www.opensource.org/licenses/artistic-license.php * Please note that the optional Clause 8 does not apply to this code. * * The Standard Version source code, and associated documentation can be found at... * [online] http://www.ccg.leeds.ac.uk/software/ * * --End of Copyright notice-- * */ /** * Basic agent class. * The class allows each agent an x and y location. * It also gets a reference to a landscape object -- each agent accesses the same landscape * object -- they just have a link to it. * The agents move randomly if they are in an area crowded with other agents. * They move randomly if this is the case. * Eventually they should end up evenly distributed. * @author Dr Andy Evans * @version 1.0 */ public class Agent { private int x = 0; private int y = 0; private Landscape landscape = null; private int densityLimit = 0; /** * Called each time iteration. * Agents check the density at their point using the landscape, and * move randomly if needs be. */ public void step() { if (landscape.getDensity(x,y) > densityLimit) { x = (new Double(Math.random()*(double)landscape.getWidth())).intValue(); y = (new Double(Math.random()*(double)landscape.getHeight())).intValue(); } } /** * Mutator for x location. */ public void setX(int x) { this.x = x; } /** * Accessor for x location. */ public int getX () { return x; } /** * Mutator for y location. */ public void setY(int y) { this.y = y; } /** * Accessor for y location. */ public int getY () { return y; } /** * For adding a reference to the landscape object. */ public void setLandscape(Landscape landscape) { this.landscape = landscape; } /** * For accessing a reference to the landscape object. */ public void setDensityLimit(int densityLimit) { this.densityLimit = densityLimit; } }