Skip to content

Commit

Permalink
Fix map with a lot of obstacles
Browse files Browse the repository at this point in the history
  • Loading branch information
5pilow committed May 17, 2024
1 parent 3ef30f0 commit 429e5f8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/java/com/leekwars/generator/maps/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ public static Map generateMap(State state, int context, int width, int height, i
}
}
}
map.setEntity(l, c);
if (c != null) {
map.setEntity(l, c);
}
}
}

map.computeComposantes();

} else {

while (!valid && nb < 63) {
while (!valid && nb++ < 63) {

map = new Map(width, height);
map.state = state;
Expand Down Expand Up @@ -206,6 +208,7 @@ public static Map generateMap(State state, int context, int width, int height, i
c = map.getRandomCell(state, t == 0 ? 1 : 4);
}
}
if (c == null) continue;

map.setEntity(l, c);
leeks.add(l);
Expand All @@ -230,7 +233,6 @@ public static Map generateMap(State state, int context, int width, int height, i
}
}
}
nb++;
}
}

Expand Down Expand Up @@ -404,20 +406,24 @@ public void clear() {

public Cell getRandomCell(State state) {
Cell retour = null;
int nb = 0;
while (retour == null || !retour.available(this)) {
retour = getCell(state.getRandom().getInt(0, nb_cells));
if (nb++ > 64) break;
}
return retour;
}

public Cell getRandomCell(State state, int part) {
Cell retour = null;
int nb = 0;
while (retour == null || !retour.available(this)) {
int y = state.getRandom().getInt(0, height - 1);
int x = state.getRandom().getInt(0, width / 4);
int cellid = y * (width * 2 - 1);
cellid += (part - 1) * width / 4 + x;
retour = getCell(cellid);
if (nb++ > 64) break;
}
return retour;
}
Expand Down

0 comments on commit 429e5f8

Please sign in to comment.