TorusPredatorsByProximitySensorBlock implements TorusPredPreySensorBlock { @Override public String[] sensorLabels(boolean isPredator) { if(isPredator){ if(Parameters.parameters.booleanParameter("predsSenseAllPrey")){ return NNTorusPredPreyController.sensorLabels(numPredators-1, "Closest Pred"); }else{ return NNTorusPredPreyController.sensorLabels(Parameters.parameters.integerParameter("numberPredsSensedByPreds"), "Closest Pred"); } }else{ if(Parameters.parameters.booleanParameter("preySenseAllPrey")){ return NNTorusPredPreyController.sensorLabels(numPredators, "Closest Pred"); }else{ return NNTorusPredPreyController.sensorLabels(Parameters.parameters.integerParameter("numberPredsSensedByPrey"), "Closest Pred"); } } } TorusPredatorsByProximitySensorBlock(); @SuppressWarnings("unchecked") @Override /** * @return the sensor inputs for the predators by proximity. The inputs will * be the X and Y offsets to each predator from this agent. Index 0 * will hold the closest predator and the last index in the array * will hold the furthest predator (array in ascending order by * distance) Distance here is defined as the sum of the absolute * value of the X and Y offsets */ double[] sensorValues(TorusAgent me, TorusWorld world, TorusAgent[] preds, TorusAgent[] prey); @Override /** * @return the total number of sensors for the predators (X and Y offsets to * each pred) */ int numSensors(boolean isPredator); @Override /** * Finds the sensor labels for this agent and returns them in an array of * Strings The sensor labels for this class will be the list of Predators * being sensed by proximity * * @return the sensorLabels for the predators by proximity */ String[] sensorLabels(boolean isPredator);  }
@Test public void testSensorLabels() { TorusPredatorsByProximitySensorBlock block = new TorusPredatorsByProximitySensorBlock(); assertEquals(Arrays.toString(block.sensorLabels(false)), "[X Offset to Closest Pred 0, Y Offset to Closest Pred 0, X Offset to Closest Pred 1, Y Offset to Closest Pred 1, " + "X Offset to Closest Pred 2, Y Offset to Closest Pred 2]"); assertEquals(Arrays.toString(block.sensorLabels(true)), "[X Offset to Closest Pred 0, Y Offset to Closest Pred 0, X Offset to Closest Pred 1, Y Offset to Closest Pred 1]"); Parameters.initializeParameterCollections(new String[] { "io:false", "netio:false", "torusTimeLimit:1000", "task:edu.utexas.cs.nn.tasks.gridTorus.TorusEvolvedPredatorsVsStaticPreyTask", "allowDoNothingActionForPredators:true", "torusPreys:2", "torusPredators:5", "staticPreyController:edu.utexas.cs.nn.gridTorus.controllers.PreyFleeClosestPredatorController", "torusSenseTeammates:true", "torusSenseByProximity:true" }); MMNEAT.loadClasses(); block = new TorusPredatorsByProximitySensorBlock(); assertEquals(Arrays.toString(block.sensorLabels(false)), "[X Offset to Closest Pred 0, Y Offset to Closest Pred 0, X Offset to Closest Pred 1, Y Offset to Closest Pred 1, " + "X Offset to Closest Pred 2, Y Offset to Closest Pred 2, X Offset to Closest Pred 3, Y Offset to Closest Pred 3, " + "X Offset to Closest Pred 4, Y Offset to Closest Pred 4]"); assertEquals(Arrays.toString(block.sensorLabels(true)), "[X Offset to Closest Pred 0, Y Offset to Closest Pred 0, X Offset to Closest Pred 1, Y Offset to Closest Pred 1, " + "X Offset to Closest Pred 2, Y Offset to Closest Pred 2, X Offset to Closest Pred 3, Y Offset to Closest Pred 3]"); }