/** * Landscape.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 landscape class. * A single landscape object is made in the model, and all agents have a reference to it. * The landscape has a reference to the array of agents created in the main * model class, so it can get each agent in turn and ask for its location. * From this, it calculates a denisty map. * In Model.java the map is then requested by each agent in turn, who uses the * densities to decide whether to move. * @author Dr Andy Evans * @version 1.0 */ public class Landscape { private int width = 0; private int height = 0; private Agent[] agents = null; // Reference to the list of agents created in Model.java. private int densities [] = null; /** * Calulates a density map. * Called each iteration in Model.java before the agents move. * Note this is a 1D array, not 2D as landscape, as it makes it easier to convert to * an image later (not that we do that here). **/ public void calcDensities() { densities = new int [width*height]; for (int i = 0; i < agents.length; i++) { densities[(agents[i].getY()*width) + agents[i].getX()]++; } } /** * Returns the density at a specific location. * Hides the complexity of 1D to 2D conversion. */ public int getDensity(int x, int y) { return densities[(y*width) + x]; } /** * Sets a reference to the agent list. */ public void setAgents (Agent[] agents) { this.agents = agents; } /** * Mutator for landscape width. */ public void setWidth(int width) { this.width= width; } /** * Accessor for landscape width. */ public int getWidth() { return width; } /** * Mutator for landscape height. */ public void setHeight(int height) { this.height = height; } /** * Accessor for landscape height. */ public int getHeight() { return height; } }