/* * file name: Landscape.java * author: YOUR NAME HERE * date: * purpose: A continuous 2D world that holds its Agents in a LinkedList. * * CS231 Project 3 - Agent-Based Simulation * * The Landscape stores its agents in YOUR LinkedList. Every method * below that looks at "all the agents" walks that list. Prefer a for-each * loop (which uses your iterator) over a loop that calls get(i): in a linked * list, get(i) has to walk from the head every single time. */ import java.awt.Graphics; import java.util.Random; public class Landscape { private int width; private int height; private LinkedList agents; // YOUR LinkedList from Lab 3 private Random gen; // ====================================================================== // TASK 4 - Building the Landscape // ====================================================================== /** * Creates an empty Landscape that is w wide and h tall. * Remember to create the (empty) agent list and the Random object. */ public Landscape(int w, int h) { // TODO (Task 4) } /** Returns the width. */ public int getWidth() { // TODO (Task 4) return 0; } /** Returns the height. */ public int getHeight() { // TODO (Task 4) return 0; } /** Returns the list of agents (the same list object, not a copy). */ public LinkedList getAgents() { // TODO (Task 4) return null; } /** Inserts an agent at the BEGINNING of the list of agents. */ public void addAgent(Agent a) { // TODO (Task 4) } /** * Returns a short description that includes the number of agents, e.g. * "Landscape 500x500 with 200 agents (120 social, 80 antisocial)" */ public String toString() { // TODO (Task 4) return ""; } /** Draws every agent. (Called by LandscapeDisplay.) */ public void draw(Graphics g) { // TODO (Task 4): ask each agent to draw itself. } // ====================================================================== // TASK 5 - Searching and changing the agent list // ====================================================================== /** * Returns a NEW LinkedList holding every agent whose distance from * (x0, y0) is less than or equal to radius. * * The agents must appear in the result in the SAME ORDER they appear in * the Landscape's list. Which of your LinkedList methods keeps that order: * add(item) or addLast(item)? * * Distance between (x1, y1) and (x2, y2): Math.sqrt(dx * dx + dy * dy) */ public LinkedList getNeighbors(double x0, double y0, double radius) { // TODO (Task 5) return new LinkedList(); } /** * Removes the agent a from the Landscape. * Returns true if a was found and removed, false if a was not in the list. * * Hint: two of your LinkedList methods do all the work: indexOf and remove(int). */ public boolean removeAgent(Agent a) { // TODO (Task 5) return false; } /** * Returns how many agents in the list are SocialAgents. * Hint: the instanceof operator. */ public int countSocialAgents() { // TODO (Task 5) return 0; } /** Returns how many agents in the list are AntiSocialAgents. */ public int countAntiSocialAgents() { // TODO (Task 5) return 0; } // ====================================================================== // TASK 7 - One step of the simulation // ====================================================================== /** * Performs one step of the simulation and returns how many agents moved. * * 0. If there are no agents, return 0. * 1. Pick a random index in the list - every index 0 .. size()-1 must be * possible - and remove that agent with remove(index). * 2. Create a new AntiSocialAgent with the removed agent's x, y and * radius, and add it with addAgent(). * 3. Call updateState(this) on every agent in the list, counting how * many of them report getMoved() == true afterwards. * 4. Return that count. * * Hint: gen.nextInt(n) returns a random int from 0 to n - 1. */ public int updateAgents() { // TODO (Task 7) return 0; } }