Package com.barrybecker4.puzzle.maze.model

Examples of com.barrybecker4.puzzle.maze.model.MazeCell


        // Keep track of our current path. We may need to backtrack along it if we encounter a dead end.
        List<Location> solutionPath = new LinkedList<Location>();

        Location currentPosition = maze.getStartPosition();
        MazeCell currentCell = maze.getCell(currentPosition);

        // push the initial moves
        stack.pushMoves( currentPosition, new IntLocation(0, 1), 1);
        panel_.paintAll();

        Location dir;
        int depth;
        boolean solved = false;

        // while there are still paths to try and we have not yet encountered the finish
        while ( !stack.isEmpty() && !solved ) {

            GenState state = stack.remove(0)// pop

            currentPosition = state.getPosition();
            solutionPath.add(0, currentPosition);

            if (currentPosition.equals(maze.getStopPosition()))  {
                solved = true;
            }

            dir = state.getDirection();
            depth = state.getDepth();
            if ( depth > currentCell.getDepth() ) {
                currentCell.setDepth(depth);
            }

            currentCell = maze.getCell(currentPosition);
            Location nextPosition = currentCell.getNextPosition(currentPosition,  dir);

            search(solutionPath, currentCell, dir, depth, nextPosition);
        }
    }
View Full Code Here


        return isWorking;
    }

    private void search(List<Location> solutionPath, MazeCell currentCell,
                        Location dir, int depth, Location nextPosition) {
        MazeCell nextCell = maze.getCell(nextPosition);
        boolean eastBlocked = dir.getX() ==  1 && currentCell.eastWall;
        boolean westBlocked =  dir.getX() == -1 && nextCell.eastWall;
        boolean southBlocked = dir.getY() ==  1 && currentCell.southWall;
        boolean northBlocked = dir.getY() == -1 && nextCell.southWall;
View Full Code Here

        GenState lastState = stack.get(0);

        Location pos;
        do {
            pos =  solutionPath.remove(0);
            MazeCell cell = maze.getCell(pos);
            cell.clearPath();
        } while ( pos != lastState.getPosition());
    }
View Full Code Here

     */
    public void search() {
        stack.clear();

        Location currentPosition = maze.getStartPosition();
        MazeCell currentCell = maze.getCell(currentPosition);
        currentCell.visited = true;

        // push the initial moves
        stack.pushMoves(currentPosition, new IntLocation(0, 1), 0);

View Full Code Here

    private MazeCell findNextCell(MazeCell lastCell) {

        boolean moved = false;

        Location currentPosition;
        MazeCell nextCell;
        int depth;
        Location dir;

        do {
            GenState state = stack.remove(0)// pop

            currentPosition = state.getPosition();
            dir = state.getDirection();
            depth = state.getDepth();

            if ( depth > maxDepth) {
                maxDepth = depth;
                maze.setStopPosition(currentPosition);
            }
            if ( depth > lastCell.getDepth() )  {
                lastCell.setDepth(depth);
            }

            MazeCell currentCell = maze.getCell(currentPosition);
            Location nextPosition = currentCell.getNextPosition(currentPosition, dir);
            nextCell = maze.getCell(nextPosition);

            if (nextCell.visited) {
                addWall(currentCell, dir, nextCell);
            }
View Full Code Here

     * Draw one of the tile paths which takes one of three forms.
     */
    public void drawPath(Graphics2D g2, int pathNumber, TilePlacement tilePlacement,
                         Point position, double size) {

        HexTile tile = tilePlacement.getTile();
        int pathStartIndex = getPathStartIndex(tile, pathNumber);

        int i = pathStartIndex + 1;

        PathColor pathColor = tile.getEdgeColor(pathStartIndex);
        while (pathColor != tile.getEdgeColor(i++)) {
            assert(i<6): "Should never exceed 6";
        }

        int pathEndIndex = i-1;
        int diff = pathEndIndex - pathStartIndex;
View Full Code Here

        this.numTiles = numTiles;
    }

    public TantrixBoard initialPosition() {
        //MathUtil.RANDOM.setSeed(1);
        return new TantrixBoard(new HexTiles().createRandomList(numTiles));
    }
View Full Code Here

    public boolean isGoal(TantrixBoard position) {
        return position.isSolved();
    }

    public TilePlacementList legalMoves(TantrixBoard position) {
        return new MoveGenerator(position).generateMoves();
    }
View Full Code Here

        HexTile tile = tilePlacement.getTile();
        int pathStartIndex = getPathStartIndex(tile, pathNumber);

        int i = pathStartIndex + 1;

        PathColor pathColor = tile.getEdgeColor(pathStartIndex);
        while (pathColor != tile.getEdgeColor(i++)) {
            assert(i<6): "Should never exceed 6";
        }

        int pathEndIndex = i-1;
View Full Code Here

     */
    private int getPathStartIndex(HexTile tile, int pathNumber) {
        Set<PathColor> set = new HashSet<PathColor>();
        int i = 0;
        do {
            PathColor c = tile.getEdgeColor(i++);
            set.add(c);
        } while (set.size() <= pathNumber);
        return i-1;
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.puzzle.maze.model.MazeCell

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.