/* * file name: AgentSimulation.java * author: YOUR NAME HERE * date: * purpose: Runs the agent-based simulation experiment. * * CS231 Project 3 - Agent-Based Simulation * * How to run: * javac *.java * java AgentSimulation 100 100 SocialAgents, with the display window * java AgentSimulation 100 off 100 SocialAgents, no window (much faster) */ import java.util.Random; public class AgentSimulation { // ====================================================================== // TASK 8 - The experiment // ====================================================================== /** * Runs one simulation and returns the number of iterations it ran. * * 1. Create a 500 x 500 Landscape. * 2. Add N SocialAgents with radius 25 at random positions inside it. * 3. If showDisplay is true, create a LandscapeDisplay for the Landscape. * 4. Loop while (the number of agents that moved in the last step is * greater than 0) AND (fewer than 5000 iterations have run): * - call updateAgents() and store how many agents moved * - count the iteration * - if showDisplay is true: repaint the display, then Thread.sleep(10) * 5. Return the number of iterations. * * Hint: before the loop, set your "moved" variable to something greater * than 0 so that the loop runs at least once. * * When showDisplay is false, do not create a LandscapeDisplay and do not * sleep. That lets the tester - and your experiments - run quickly. */ public static int runExpt(int N, boolean showDisplay) throws InterruptedException { // TODO (Task 8) return 0; } public static void main(String[] args) throws InterruptedException { int N = 100; if (args.length > 0) { N = Integer.parseInt(args[0]); } boolean show = !(args.length > 1 && args[1].equalsIgnoreCase("off")); int iterations = runExpt(N, show); System.out.println("N = " + N + ": the simulation ran for " + iterations + " iterations."); // EXPLORATION: you may add code here (or in another method) that runs // several trials of runExpt(N, false) for each N and reports the results. } }