Corrected directions

This commit is contained in:
David Alves
2025-10-29 22:36:58 +00:00
parent 4772add574
commit dab0651dbd

View File

@@ -83,33 +83,23 @@ public class IntersectionProcess {
private void createTrafficLights() { private void createTrafficLights() {
System.out.println("\n[" + intersectionId + "] Creating traffic lights..."); System.out.println("\n[" + intersectionId + "] Creating traffic lights...");
// Define directions based on the actual network topology String[] directions = new String[0];
String[] directions;
switch (intersectionId) { switch (intersectionId) {
case "Cr1": case "Cr1":
// Cr1: East (to Cr2), South (to Cr4), West (from Cr2) directions = new String[]{"East", "South"};
directions = new String[]{"East", "South", "West"};
break; break;
case "Cr2": case "Cr2":
// Cr2: West (to Cr1), East (to Cr3), South (to Cr5)
// Plus receiving from Cr1 and Cr3
directions = new String[]{"West", "East", "South"}; directions = new String[]{"West", "East", "South"};
break; break;
case "Cr3": case "Cr3":
// Cr3: West (to Cr2), East (to S) directions = new String[]{"West", "South"};
directions = new String[]{"West", "East"};
break; break;
case "Cr4": case "Cr4":
// Cr4: East (to Cr5), plus pedestrian crossing
directions = new String[]{"East"}; directions = new String[]{"East"};
break; break;
case "Cr5": case "Cr5":
// Cr5: East (to S), receives from Cr2 and Cr4
directions = new String[]{"East"}; directions = new String[]{"East"};
break; break;
default:
// Fallback to all directions
directions = new String[]{"North", "South", "East", "West"};
} }
for (String direction : directions) { for (String direction : directions) {
@@ -134,41 +124,31 @@ public class IntersectionProcess {
switch (intersectionId) { switch (intersectionId) {
case "Cr1": case "Cr1":
// Cr1 connections: → Cr2 (East), → Cr4 (South), ← Cr2 (West) intersection.configureRoute("Cr2", "East");
intersection.configureRoute("Cr2", "East"); // Go to Cr2 intersection.configureRoute("Cr4", "South");
intersection.configureRoute("Cr4", "South"); // Go to Cr4
// Routes through other intersections to reach S
intersection.configureRoute("S", "East"); // S via Cr2
break; break;
case "Cr2": case "Cr2":
// Cr2 connections: ↔ Cr1 (West/East), ↔ Cr3 (East/West), → Cr5 (South) intersection.configureRoute("Cr1", "West");
intersection.configureRoute("Cr1", "West"); // Go to Cr1 intersection.configureRoute("Cr3", "East");
intersection.configureRoute("Cr3", "East"); // Go to Cr3 intersection.configureRoute("Cr5", "South");
intersection.configureRoute("Cr5", "South"); // Go to Cr5
intersection.configureRoute("S", "South"); // S via Cr5 or direct
break; break;
case "Cr3": case "Cr3":
// Cr3 connections: ← Cr2 (West), → S (South/East) intersection.configureRoute("Cr2", "West");
intersection.configureRoute("Cr2", "West"); // Go back to Cr2 intersection.configureRoute("S", "South");
intersection.configureRoute("S", "East"); // Go to exit S
break; break;
case "Cr4": case "Cr4":
// Cr4 connections: → Cr5 (East) intersection.configureRoute("Cr5", "East");
intersection.configureRoute("Cr5", "East"); // Go to Cr5
intersection.configureRoute("S", "East"); // S via Cr5
break; break;
case "Cr5": case "Cr5":
// Cr5 connections: → S (East/South) intersection.configureRoute("S", "East");
intersection.configureRoute("S", "East"); // Go to exit S
// Cr5 might also receive from Cr2 and Cr4 but doesn't route back
break; break;
default: default:
System.err.println(" Warning: Unknown intersection ID: " + intersectionId); System.err.println(" Error: unknown intersection ID: " + intersectionId);
} }
System.out.println(" Routing configured."); System.out.println(" Routing configured.");