Examples of MazeCell


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

    private void drawVisitedCells(Graphics2D g2, MazeModel maze) {

        g2.setColor( VISITED_COLOR );
        for (int j = 0; j < maze.getHeight(); j++ ) {
            for (int i = 0; i < maze.getWidth(); i++ ) {
                MazeCell c = maze.getCell(i, j);
                assert c != null : "Error1 pos i=" + i + " j=" + j + " is out of bounds." ;
                int xpos = i * cellSize;
                int ypos = j * cellSize;

                if ( c.visited ) {
View Full Code Here

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

        g2.setStroke( wallStroke );
        g2.setColor( WALL_COLOR );
        for (int j = 0; j < maze.getHeight(); j++ ) {
            for (int i = 0; i < maze.getWidth(); i++ ) {
                MazeCell c = maze.getCell(i, j);
                assert ( c != null ) : "Error2 pos i=" + i + " j=" + j  + " is out of bounds.";

                int xpos = i * cellSize;
                int ypos = j * cellSize;

 
View Full Code Here

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

        g2.setStroke( pathStroke );
        g2.setColor( PATH_COLOR );

        for (int j = 0; j < maze.getHeight(); j++ ) {
            for (int i = 0; i < maze.getWidth(); i++ ) {
                MazeCell c = maze.getCell(i,  j);
                int xpos = i * cellSize;
                int ypos = j * cellSize;

                assert c != null;
                if ( c.eastPath )  {
View Full Code Here

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

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

        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

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

        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

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

     */
    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

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

    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

Examples of maze.model.MazeCell

    * only one entrance/exit associated with the goal.
    */
   private void blockOutCenter()
   {
      Dimension size = maze.getSize();
      MazeCell cell1 = MazeCell.valueOf(size.width / 2, size.height / 2);
      MazeCell cell2 = MazeCell.valueOf(size.width / 2 + 1, size.height / 2);
      MazeCell cell3 = MazeCell.valueOf(size.width / 2, size.height / 2 + 1);
      MazeCell cell4 = MazeCell.valueOf(size.width / 2 + 1, size.height / 2 + 1);
      MazeCell current = robotLocation.getCurrentLocation();

      if (cell1.equals(current) == false)
      {
         maze.setWall(cell1.getX(), cell1.getY(), Direction.North.getIndex());
         maze.setWall(cell1.getX(), cell1.getY(), Direction.West.getIndex());
View Full Code Here

Examples of maze.model.MazeCell

    * Returns true if the current location of the robot is its current
    * destination.
    */
   private boolean atGoal()
   {
      MazeCell cell = robotLocation.getCurrentLocation();
      Dimension size = maze.getSize();
      if ( (goal == TO_START) && (cell.getX() == 1) && (cell.getY() == size.height))
      {
         return true;
      }
      if ( (goal == TO_CENTER) &&
          ( (cell.getY() == size.height / 2) || (cell.getY() == (size.height / 2 + 1))) &&
          ( (cell.getX() == size.width / 2) || (cell.getX() == (size.width / 2 + 1))))
      {
         return true;
      }
      return false;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.