@Test public void getNextCycle3() { List<CarSimulationResult> results = new ArrayList<>(); results.add(new CarSimulationResult(new CarConfiguration(car, null, null, null, null, null), 0, false, false)); results = rs.next(new RaceSimulationResult(results, false)).getResults(); if (results.get(0).hasCrashed()) { assertEquals(0, results.get(0).getDistanceTraveled(), 0.01); return; } assertNotEquals(0, results.get(0).getDistanceTraveled(), 0.01); }
public RaceSimulationResult next(RaceSimulationResult previous) { final List<CarSimulationResult> results = new ArrayList<>(); final Map<Boolean, List<CarSimulationResult>> split = previous.getResults() .stream() .collect(Collectors.partitioningBy(CarSimulationResult::hasFinished)); results.addAll(split.get(true)); split.get(false) .stream() .map(result -> { final CarSimulator cs = simulators.get(result.getConfiguration().getCar()); if (cs.hasCrashed(raining, cs.isNearby(result, previous, 100), random)) { return result.crash(); } return result .increaseDistance(cs.calculateDelta(random)) .finishOn(grandPrix.getCircuit().getLength()); }) .sorted(Comparator.comparingDouble(CarSimulationResult::getDistanceTraveled).reversed()) .forEachOrdered(results::add); return createResult(results); }
RaceSimulator implements Iterable<RaceSimulationResult> { public RaceSimulationResult next(RaceSimulationResult previous) { final List<CarSimulationResult> results = new ArrayList<>(); final Map<Boolean, List<CarSimulationResult>> split = previous.getResults() .stream() .collect(Collectors.partitioningBy(CarSimulationResult::hasFinished)); results.addAll(split.get(true)); split.get(false) .stream() .map(result -> { final CarSimulator cs = simulators.get(result.getConfiguration().getCar()); if (cs.hasCrashed(raining, cs.isNearby(result, previous, 100), random)) { return result.crash(); } return result .increaseDistance(cs.calculateDelta(random)) .finishOn(grandPrix.getCircuit().getLength()); }) .sorted(Comparator.comparingDouble(CarSimulationResult::getDistanceTraveled).reversed()) .forEachOrdered(results::add); return createResult(results); } }
RaceSimulator implements Iterable<RaceSimulationResult> { public RaceSimulationResult next(RaceSimulationResult previous) { final List<CarSimulationResult> results = new ArrayList<>(); final Map<Boolean, List<CarSimulationResult>> split = previous.getResults() .stream() .collect(Collectors.partitioningBy(CarSimulationResult::hasFinished)); results.addAll(split.get(true)); split.get(false) .stream() .map(result -> { final CarSimulator cs = simulators.get(result.getConfiguration().getCar()); if (cs.hasCrashed(raining, cs.isNearby(result, previous, 100), random)) { return result.crash(); } return result .increaseDistance(cs.calculateDelta(random)) .finishOn(grandPrix.getCircuit().getLength()); }) .sorted(Comparator.comparingDouble(CarSimulationResult::getDistanceTraveled).reversed()) .forEachOrdered(results::add); return createResult(results); } RaceSimulator(Map<Car, CarSimulator> simulators, GrandPrix grandPrix, Random random);  RaceSimulator(Map<Car, CarSimulator> simulators, GrandPrix grandPrix);  RaceSimulator(Collection<CarSimulator> simulators, GrandPrix grandPrix); }
RaceSimulator implements Iterable<RaceSimulationResult> { public RaceSimulationResult next(RaceSimulationResult previous) { final List<CarSimulationResult> results = new ArrayList<>(); final Map<Boolean, List<CarSimulationResult>> split = previous.getResults() .stream() .collect(Collectors.partitioningBy(CarSimulationResult::hasFinished)); results.addAll(split.get(true)); split.get(false) .stream() .map(result -> { final CarSimulator cs = simulators.get(result.getConfiguration().getCar()); if (cs.hasCrashed(raining, cs.isNearby(result, previous, 100), random)) { return result.crash(); } return result .increaseDistance(cs.calculateDelta(random)) .finishOn(grandPrix.getCircuit().getLength()); }) .sorted(Comparator.comparingDouble(CarSimulationResult::getDistanceTraveled).reversed()) .forEachOrdered(results::add); return createResult(results); } RaceSimulator(Map<Car, CarSimulator> simulators, GrandPrix grandPrix, Random random);  RaceSimulator(Map<Car, CarSimulator> simulators, GrandPrix grandPrix);  RaceSimulator(Collection<CarSimulator> simulators, GrandPrix grandPrix); Collection<CarSimulator> getSimulators(); GrandPrix getGrandPrix(); boolean isRaining(); RaceSimulationResult start(); RaceSimulationResult next(RaceSimulationResult previous); @Override Iterator<RaceSimulationResult> iterator(); }
RaceSimulator implements Iterable<RaceSimulationResult> { public RaceSimulationResult next(RaceSimulationResult previous) { final List<CarSimulationResult> results = new ArrayList<>(); final Map<Boolean, List<CarSimulationResult>> split = previous.getResults() .stream() .collect(Collectors.partitioningBy(CarSimulationResult::hasFinished)); results.addAll(split.get(true)); split.get(false) .stream() .map(result -> { final CarSimulator cs = simulators.get(result.getConfiguration().getCar()); if (cs.hasCrashed(raining, cs.isNearby(result, previous, 100), random)) { return result.crash(); } return result .increaseDistance(cs.calculateDelta(random)) .finishOn(grandPrix.getCircuit().getLength()); }) .sorted(Comparator.comparingDouble(CarSimulationResult::getDistanceTraveled).reversed()) .forEachOrdered(results::add); return createResult(results); } RaceSimulator(Map<Car, CarSimulator> simulators, GrandPrix grandPrix, Random random);  RaceSimulator(Map<Car, CarSimulator> simulators, GrandPrix grandPrix);  RaceSimulator(Collection<CarSimulator> simulators, GrandPrix grandPrix); Collection<CarSimulator> getSimulators(); GrandPrix getGrandPrix(); boolean isRaining(); RaceSimulationResult start(); RaceSimulationResult next(RaceSimulationResult previous); @Override Iterator<RaceSimulationResult> iterator();  }