Search in sources :

Example 11 with LineWall

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));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LineWall(src.model.board.LineWall) ContentMaze(src.model.ContentMaze) Random(java.util.Random)

Example 12 with LineWall

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);
    }
}
Also used : LineWall(src.model.board.LineWall) TimeCase(src.model.board.TimeCase) EndCase(src.model.board.EndCase) JumpCase(src.model.board.JumpCase) Case(src.model.board.Case) StartCase(src.model.board.StartCase) SpeedCase(src.model.board.SpeedCase) TeleportCase(src.model.board.TeleportCase)

Example 13 with LineWall

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);
            }
        }
    }
}
Also used : LineWall(src.model.board.LineWall)

Example 14 with LineWall

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);
}
Also used : LineWall(src.model.board.LineWall)

Example 15 with LineWall

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);
}
Also used : LineWall(src.model.board.LineWall) ContentMazeEgg(src.model.gen.ContentMazeEgg) RectMaze(src.model.gen.RectMaze)

Aggregations

LineWall (src.model.board.LineWall)18 RectMaze (src.model.gen.RectMaze)8 ContentMazeEgg (src.model.gen.ContentMazeEgg)7 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Group (javafx.scene.Group)2 ContentMaze (src.model.ContentMaze)2 FileInputStream (java.io.FileInputStream)1 Map (java.util.Map)1 Random (java.util.Random)1 AmbientLight (javafx.scene.AmbientLight)1 Image (javafx.scene.image.Image)1 Material (javafx.scene.paint.Material)1 PhongMaterial (javafx.scene.paint.PhongMaterial)1 Box (javafx.scene.shape.Box)1 Line (javafx.scene.shape.Line)1 Case (src.model.board.Case)1 EndCase (src.model.board.EndCase)1 JumpCase (src.model.board.JumpCase)1 SpeedCase (src.model.board.SpeedCase)1