mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-08 12:33:31 +00:00
Corrected directions
This commit is contained in:
@@ -83,33 +83,23 @@ public class IntersectionProcess {
|
||||
private void createTrafficLights() {
|
||||
System.out.println("\n[" + intersectionId + "] Creating traffic lights...");
|
||||
|
||||
// Define directions based on the actual network topology
|
||||
String[] directions;
|
||||
String[] directions = new String[0];
|
||||
switch (intersectionId) {
|
||||
case "Cr1":
|
||||
// Cr1: East (to Cr2), South (to Cr4), West (from Cr2)
|
||||
directions = new String[]{"East", "South", "West"};
|
||||
directions = new String[]{"East", "South"};
|
||||
break;
|
||||
case "Cr2":
|
||||
// Cr2: West (to Cr1), East (to Cr3), South (to Cr5)
|
||||
// Plus receiving from Cr1 and Cr3
|
||||
directions = new String[]{"West", "East", "South"};
|
||||
break;
|
||||
case "Cr3":
|
||||
// Cr3: West (to Cr2), East (to S)
|
||||
directions = new String[]{"West", "East"};
|
||||
directions = new String[]{"West", "South"};
|
||||
break;
|
||||
case "Cr4":
|
||||
// Cr4: East (to Cr5), plus pedestrian crossing
|
||||
directions = new String[]{"East"};
|
||||
break;
|
||||
case "Cr5":
|
||||
// Cr5: East (to S), receives from Cr2 and Cr4
|
||||
directions = new String[]{"East"};
|
||||
break;
|
||||
default:
|
||||
// Fallback to all directions
|
||||
directions = new String[]{"North", "South", "East", "West"};
|
||||
}
|
||||
|
||||
for (String direction : directions) {
|
||||
@@ -134,41 +124,31 @@ public class IntersectionProcess {
|
||||
|
||||
switch (intersectionId) {
|
||||
case "Cr1":
|
||||
// Cr1 connections: → Cr2 (East), → Cr4 (South), ← Cr2 (West)
|
||||
intersection.configureRoute("Cr2", "East"); // Go to Cr2
|
||||
intersection.configureRoute("Cr4", "South"); // Go to Cr4
|
||||
// Routes through other intersections to reach S
|
||||
intersection.configureRoute("S", "East"); // S via Cr2
|
||||
intersection.configureRoute("Cr2", "East");
|
||||
intersection.configureRoute("Cr4", "South");
|
||||
break;
|
||||
|
||||
case "Cr2":
|
||||
// Cr2 connections: ↔ Cr1 (West/East), ↔ Cr3 (East/West), → Cr5 (South)
|
||||
intersection.configureRoute("Cr1", "West"); // Go to Cr1
|
||||
intersection.configureRoute("Cr3", "East"); // Go to Cr3
|
||||
intersection.configureRoute("Cr5", "South"); // Go to Cr5
|
||||
intersection.configureRoute("S", "South"); // S via Cr5 or direct
|
||||
intersection.configureRoute("Cr1", "West");
|
||||
intersection.configureRoute("Cr3", "East");
|
||||
intersection.configureRoute("Cr5", "South");
|
||||
break;
|
||||
|
||||
case "Cr3":
|
||||
// Cr3 connections: ← Cr2 (West), → S (South/East)
|
||||
intersection.configureRoute("Cr2", "West"); // Go back to Cr2
|
||||
intersection.configureRoute("S", "East"); // Go to exit S
|
||||
intersection.configureRoute("Cr2", "West");
|
||||
intersection.configureRoute("S", "South");
|
||||
break;
|
||||
|
||||
case "Cr4":
|
||||
// Cr4 connections: → Cr5 (East)
|
||||
intersection.configureRoute("Cr5", "East"); // Go to Cr5
|
||||
intersection.configureRoute("S", "East"); // S via Cr5
|
||||
intersection.configureRoute("Cr5", "East");
|
||||
break;
|
||||
|
||||
case "Cr5":
|
||||
// Cr5 connections: → S (East/South)
|
||||
intersection.configureRoute("S", "East"); // Go to exit S
|
||||
// Cr5 might also receive from Cr2 and Cr4 but doesn't route back
|
||||
intersection.configureRoute("S", "East");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.err.println(" Warning: Unknown intersection ID: " + intersectionId);
|
||||
System.err.println(" Error: unknown intersection ID: " + intersectionId);
|
||||
}
|
||||
|
||||
System.out.println(" Routing configured.");
|
||||
|
||||
Reference in New Issue
Block a user