From 072b37ece74a62fa7b859a7111e1072e776eae5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20GUEZO?= Date: Wed, 29 Oct 2025 16:00:21 +0100 Subject: [PATCH] fix(Map.java): modif des fonc bind, follow et build path - `bindPath`: `Point(i, j)` -> `Point(j, i)` - `buildPath`: init ArrayList - `followPath`: ajout current == ROAD ET next == FINISH --- src/Map.java | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/Map.java b/src/Map.java index c047d10..7277f44 100644 --- a/src/Map.java +++ b/src/Map.java @@ -9,7 +9,13 @@ public class Map public Map(Circuit[][] map) { this.map = map; - this.buildPath(); + boolean isPossible = this.buildPath(); + + if (!isPossible) + { + System.err.println("La map contient des doublons ou est impossible à finir!"); + System.exit(1); + } } private boolean buildPath() @@ -20,8 +26,9 @@ public class Map return false; Point start = p[0]; - Point end = p[0]; + Point end = p[1]; + this.pathMap = new ArrayList<>(); return followPath(start, end); } @@ -37,11 +44,11 @@ public class Map switch (map[i][j].getType()) { case CircuitCell.START: - if (start == null) start = new Point(i, j); + if (start == null) start = new Point(j, i); else return null; break; case CircuitCell.FINISH: - if (end == null) end = new Point(i, j); + if (end == null) end = new Point(j, i); else return null; break; default: @@ -49,7 +56,7 @@ public class Map } } } - + if (start == null || end == null) return null; return new Point[] {start, end}; } @@ -68,14 +75,14 @@ public class Map {0, -1}, // gauche {0, 1} // droite }; - + // sécurité pour éviter les boucles infinie int step = 0; int max = map.length * map[0].length; for (; step < max; step++) { pathMap.add(current); - + if (current.equals(end)) return true; @@ -86,7 +93,7 @@ public class Map int x = current.x + pos[0]; int y = current.y + pos[1]; - if ((x >= 0 || map[0].length > x) || (y >= 0 || map.length > y)) + if ((x >= 0 && map[0].length > x) && (y >= 0 && map.length > y)) { Point next = new Point(x, y); @@ -94,8 +101,8 @@ public class Map continue; CircuitCell type = map[y][x].getType(); - if (type == CircuitCell.FINISH || type == CircuitCell.ROAD - || type == CircuitCell.YROAD) + if ((type == CircuitCell.ROAD || type == CircuitCell.YROAD) || + (type == CircuitCell.FINISH && map[current.y][current.x] == CircuitCell.ROAD)) { previous = current; current = next; @@ -104,6 +111,7 @@ public class Map } } } + // Si il est bloqué if (!moved) break; }