Compare commits

...

1 Commits

Author SHA1 Message Date
82efe228d3
Ugly implementation. Looks slower?! 2020-11-27 21:11:21 +03:00

View File

@ -1,4 +1,5 @@
import java.util.*;
import java.util.concurrent.ThreadPoolExecutor;
public class MakkahCity {
@ -66,6 +67,7 @@ public class MakkahCity {
}
clearDoneCivilVehicles();
ArrayList<Thread> threadPool = new ArrayList<>();
for (Vehicle vehicle : listOfVehicles) {
Route route = vehicle.getRoute();
double currentLocation = vehicle.getCurrentLocation();
@ -81,6 +83,8 @@ public class MakkahCity {
vehicle.moveToNextStreet();
}
if (!vehicle.isArrivedToDest()) {
Thread t = new Thread(() -> {
try {
double factor = 1-(vehicle.getCurrentStreet().capcityPoint(vehicle.getCurrentLocation(),
vehicle.getCurrentLocation()+1000,vehicle)) ;
if (vehicle instanceof Bus) vehicle.move(Bus.MAX_FORWARD * factor );
@ -88,6 +92,21 @@ public class MakkahCity {
else if (vehicle instanceof SUV) vehicle.move(SUV.MAX_FORWARD * factor );
else if (vehicle instanceof Truck) vehicle.move(Bus.MAX_FORWARD * factor );
}
catch (Exception e) {
//e.printStackTrace();
}
});
threadPool.add(t);
t.start();
}
}
}
for (Thread t : threadPool) {
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//noise based on time of day (From PDate)