/** Implements simulation initialization */ public void start() { // Start the simulation super.start(); // Clear the field of food and robots field.clear(); // Reset the scores score[0] = score[1] = 0; // Add our team of robots to the field and activate them Team team = new Team(field, false, strategy); schedule.scheduleRepeating(team); // Add the opposing team of robots to the field and activate them Team opposingTeam = new Team(field, true, baselineStrategy); schedule.scheduleRepeating(opposingTeam); // Add some randomly distributed food to the field for (int t = 0; t < nTreats; t++) { // Select a random but empty location Double2D treatLocation; do { treatLocation = new Double2D( field.getWidth() * (random.nextDouble() * 0.8 + 0.1), field.getHeight() * (random.nextDouble() * 0.8 + 0.1)); } while (field.getObjectsWithinDistance(treatLocation, Treat.treatSize).size() > 0); Treat treat = new Treat(); field.setObjectLocation(treat, treatLocation); } }
public void start() { super.start(); // clear the yard yard.clear(); // clear the buddies buddies.clear(); // add some students to the yard for (int i = 0; i < numStudents; i++) { Student student = new Student(); yard.setObjectLocation( student, new Double2D( yard.getWidth() * 0.5 + random.nextDouble() - 0.5, yard.getHeight() * 0.5 + random.nextDouble() - 0.5)); buddies.addNode(student); schedule.scheduleRepeating(student); } // define like/dislike relationships Bag students = buddies.getAllNodes(); for (int i = 0; i < students.size(); i++) { Object student = students.get(i); // who does he like? Object studentB = null; do { studentB = students.get(random.nextInt(students.numObjs)); } while (student == studentB); double buddiness = random.nextDouble(); buddies.addEdge(student, studentB, new Double(buddiness)); // who does he dislike? do { studentB = students.get(random.nextInt(students.numObjs)); } while (student == studentB); buddiness = random.nextDouble(); buddies.addEdge(student, studentB, new Double(-buddiness)); } }