public static double runTrial(int memoryType, int probability) { HashMap<Point, EnergySource> energySources = new HashMap<>(); int sources = 40, width = 200, height = 200, energy = 125; Point location = new Point(0, 0); Random generator = new Random(); Robot<EnergySource> robot; EnergySource energySource; double amount; // Generate all the energy sources and the robot while (energySources.size() < sources) { location = new Point(generator.nextInt(width), generator.nextInt(height)); if (isFarEnough(location, energySources)) { energySources.put(location, new EnergySource(location, energy)); } } while (!isFarEnough(location, energySources)) { location = new Point(generator.nextInt(width), generator.nextInt(height)); } robot = new Robot<>(location, memoryType); // Program loop while (robot.getEnergy() > 0) { if (robot.isCurious()) { robot.moveRandomly(width, height); } else { energySource = robot.retrieveEnergySource(probability); if (energySource != null) { robot.moveToLocation(energySource.getLocation()); } else { robot.moveRandomly(width, height); } energySource = energySources.get(robot.getLocation()); if (energySource != null) { if (robot.getMaxEnergy() - robot.getEnergy() < energySource.getEnergy()) { amount = robot.getMaxEnergy() - robot.getEnergy(); } else { amount = energySource.getEnergy(); } robot.increaseEnergy(amount); energySource.decreaseEnergy(amount); if (energySource.getEnergy() <= 0) { robot.forgetEnergySource(energySource); energySources.remove(robot.getLocation()); } } } robot.detectEnergySources(energySources); } return robot.getTravelDistance(); }