use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.
the class AlgoBackTracker method buildWalls.
private LineWall[] buildWalls(int size_x, int size_y) {
HashMap<Integer, ArrayList<LineWall>> list_X = new HashMap<>();
HashMap<Integer, ArrayList<LineWall>> list_Y = new HashMap<>();
ArrayList<Point> unvisited_cases = new ArrayList<>();
ArrayList<Point> neighborhoods = null;
Point current_position_agent = null;
Point ptActu = null;
Point res = null;
Point next = null;
Random ran = new Random();
// Initialize Walls : Fill it
for (int i = 0; i <= size_y; i++) {
ArrayList<LineWall> tmp = new ArrayList<>();
tmp.add(LineWall.buildDirectedLineWall(true, 0, size_x, i));
list_X.put(i, tmp);
}
for (int j = 0; j <= size_x; j++) {
ArrayList<LineWall> tmp = new ArrayList<>();
tmp.add(LineWall.buildDirectedLineWall(false, 0, size_y, j));
list_Y.put(j, tmp);
}
for (int i = 0; i < size_y; i++) {
for (int j = 0; j < size_x; j++) {
unvisited_cases.add(new Point(i, j));
}
}
current_position_agent = Point.getArrayList(unvisited_cases, ran.nextInt(size_y), ran.nextInt(size_x));
unvisited_cases.remove(current_position_agent);
while (unvisited_cases.isEmpty() == false) {
neighborhoods = new ArrayList<>();
if ((ptActu = Point.getArrayListLeft(unvisited_cases, current_position_agent)) != null) {
neighborhoods.add(ptActu);
}
if ((ptActu = Point.getArrayListRight(unvisited_cases, current_position_agent)) != null) {
neighborhoods.add(ptActu);
}
if ((ptActu = Point.getArrayListUp(unvisited_cases, current_position_agent)) != null) {
neighborhoods.add(ptActu);
}
if ((ptActu = Point.getArrayListDown(unvisited_cases, current_position_agent)) != null) {
neighborhoods.add(ptActu);
}
if (neighborhoods.isEmpty()) {
current_position_agent = Point.getRandomWhenNoNeighboors(unvisited_cases, size_y, size_x, ran);
continue;
}
next = neighborhoods.get(ran.nextInt(neighborhoods.size()));
unvisited_cases.remove(next);
Point.removeWalls(list_Y, list_X, current_position_agent, next);
current_position_agent = next;
if (DEBUG_MODE) {
DisplayMazeConsole.displayMaze(new ContentMaze[] { new ContentMaze(null, buildFinal(list_X, list_Y), null) }, false);
try {
Thread.sleep(50);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
return (buildFinal(list_Y, list_X));
}
use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.
the class ContentMazeFactory method reallyAddRectMazeShift.
private void reallyAddRectMazeShift(RectMazeShift cms) {
ContentMazeEgg cm;
cm = cms.getTranslatedContentMaze();
LineWall[] lw = cm.getLineWalls();
for (LineWall l : lw) {
this.addWall(l);
}
Case[] cs = cm.getSpecialCases();
for (Case c : cs) {
this.addSpecialCase(c);
}
}
use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.
the class ContentMazeFactory method addingDoors.
private void addingDoors(RectMazeShift cms, int x1, int x2, int y1, int y2) {
// Handle row x1
ArrayList<LineWall> li;
li = new ArrayList<>();
li.addAll(calculateIntersection(this.contentX.get(x1), new LineWall(x1, y1, x1, y2)));
li.addAll(calculateIntersection(this.contentX.get(x2), new LineWall(x2, y1, x2, y2)));
li.addAll(calculateIntersection(this.contentY.get(y1), new LineWall(x1, y1, x2, y1)));
li.addAll(calculateIntersection(this.contentY.get(y2), new LineWall(x1, y2, x2, y2)));
for (LineWall lw : li) {
LineWall lres;
int nb_door;
int[] index_doors;
boolean mode;
nb_door = (lw.getSize() - 1) / 5 + 1;
index_doors = DiscreteStatMazeGenerator.getKParmiN(nb_door, lw.getSize());
mode = lw.isHorizontal();
for (int i : index_doors) {
if (mode) {
lres = new LineWall(lw.getX1() + i - 1, lw.getY1(), lw.getX1() + i, lw.getY1());
if (this.listDoorsY.containsKey(lw.getY1()) == false) {
this.listDoorsY.put(lw.getY1(), new ArrayList<LineWall>());
}
this.listDoorsY.get(lw.getY1()).add(lres);
} else {
lres = new LineWall(lw.getX1(), lw.getY1() + i - 1, lw.getX1(), lw.getY1() + i);
if (this.listDoorsX.containsKey(lw.getX1()) == false) {
this.listDoorsX.put(lw.getX1(), new ArrayList<LineWall>());
}
this.listDoorsX.get(lw.getX1()).add(lres);
}
}
}
}
use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.
the class ContentMazeFactory method calculateIntersection.
private ArrayList<LineWall> calculateIntersection(ArrayList<LineWall> content, LineWall actu) {
ArrayList<LineWall> result;
result = new ArrayList<>();
if (content != null) {
for (LineWall lw : content) {
LineWall linter;
linter = LineWallUtils.intersection(lw, actu);
if (linter != null) {
result.add(linter);
}
}
}
return (result);
}
use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.
the class MapIntro4 method buildOneSquareLabyrinthe.
private RectMaze buildOneSquareLabyrinthe() {
RectMaze rl;
ArrayList<LineWall> listWalls;
listWalls = new ArrayList<>();
listWalls.add(new LineWall(0, 0, 0, 4));
listWalls.add(new LineWall(7, 4, 7, 0));
listWalls.add(new LineWall(0, 0, 7, 0));
listWalls.add(new LineWall(0, 4, 7, 4));
listWalls.add(new LineWall(1, 0, 1, 3));
listWalls.add(new LineWall(2, 3, 6, 3));
listWalls.add(new LineWall(1, 2, 5, 2));
listWalls.add(new LineWall(5, 2, 5, 1));
listWalls.add(new LineWall(5, 1, 2, 1));
listWalls.add(new LineWall(6, 3, 6, 1));
rl = new RectMaze(new ContentMazeEgg(new Case[0], listWalls.toArray(new LineWall[0])), 7, 4);
return (rl);
}
Aggregations