@Override public void start() { super.start(); environment = new Continuous2D(1.0, config.getEnvironmentWidth(), config.getEnvironmentHeight()); drawProxy = new DrawProxy(environment.getWidth(), environment.getHeight()); environment.setObjectLocation(drawProxy, new Double2D()); physicsWorld = new World(new Vec2()); placementArea = new PlacementArea((float) environment.getWidth(), (float) environment.getHeight()); placementArea.setSeed(config.getSimulationSeed()); schedule.reset(); System.gc(); physicsWorld.setContactListener(contactListener); // Create ALL the objects createWalls(); createTargetArea(); robotFactory.placeInstances( placementArea.new ForType<>(), physicsWorld, config.getTargetAreaPlacement()); config.getResourceFactory().placeInstances(placementArea.new ForType<>(), physicsWorld); // Now actually add the objects that have been placed to the world and schedule for (PhysicalObject object : placementArea.getPlacedObjects()) { drawProxy.registerDrawable(object.getPortrayal()); schedule.scheduleRepeating(object); } schedule.scheduleRepeating( simState -> physicsWorld.step(TIME_STEP, VELOCITY_ITERATIONS, POSITION_ITERATIONS)); }
/** 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); } }
@Override public void start() { super.start(); par = originalPar.clone(); par.shepherdLinearSpeed += par.shepherdLinearSpeed * par.actuatorOffset * (random.nextDouble() * 2 - 1); par.shepherdTurnSpeed += par.shepherdTurnSpeed * par.actuatorOffset * (random.nextDouble() * 2 - 1); par.shepherdSensorRange += par.shepherdSensorRange * par.sensorOffset * (random.nextDouble() * 2 - 1); // Static environment fence = new StaticPolygon( new Segment(0, 0, par.arenaSize, 0), new Segment(par.arenaSize, 0, par.arenaSize, par.arenaSize / 2 - par.gateSize / 2), new Segment( par.arenaSize, par.arenaSize / 2 + par.gateSize / 2, par.arenaSize, par.arenaSize), new Segment(par.arenaSize, par.arenaSize, 0, par.arenaSize)); fence.paint = Color.BLACK; openSide = new StaticPolygon(new Segment(0, 0, 0, par.arenaSize)); openSide.paint = Color.RED; curral = new StaticPolygon( new Segment( par.arenaSize, par.arenaSize / 2 - par.gateSize / 2, par.arenaSize, par.arenaSize / 2 + par.gateSize / 2)); curral.paint = Color.BLUE; this.field = new Continuous2D(par.discretization, par.arenaSize, par.arenaSize); placeSheeps(); placeFoxes(); placeShepherds(); field.setObjectLocation(fence, new Double2D(0, 0)); field.setObjectLocation(openSide, new Double2D(0, 0)); field.setObjectLocation(curral, new Double2D(0, 0)); this.td = new TaskDescription( new GenericDistanceFunction(field), new EntityGroup(shepherds, shepherds.size(), shepherds.size(), false), new EntityGroup(activeSheeps, 0, sheeps.size(), false), new EntityGroup(foxes, foxes.size(), foxes.size(), false), new EntityGroup(Collections.singletonList(fence), 1, 1, true), new EntityGroup(Collections.singletonList(openSide), 1, 1, true), new EntityGroup(Collections.singletonList(curral), 1, 1, true)); }
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)); } }