Package maze.model

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


    * 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

    * Updates the algorithm's memory of the maze based upon the walls in the
    * current cell.
    */
   private void checkWalls()
   {
      MazeCell cell = robotLocation.getCurrentLocation();
      Direction direction = robotLocation.getDirection();
      if (robotLocation.isWallFront())
      {
         maze.setWall(cell.getX(), cell.getY(), direction.getIndex());
      }
      if (robotLocation.isWallLeft())
      {
         maze.setWall(cell.getX(), cell.getY(), direction.getLeft().getIndex());
      }
      if (robotLocation.isWallRight())
      {
         maze.setWall(cell.getX(), cell.getY(), direction.getRight().getIndex());
      }
      if (robotLocation.isWallBack())
      {
         maze.setWall(cell.getX(), cell.getY(), direction.getOpposite().getIndex());
      }
   }
View Full Code Here

    * Returns the explored flag of the current location's neighbor in the given
    * direction.
    */
   private boolean getNeighborExplored(Direction direction)
   {
      MazeCell neighbor;
      MazeCell here = robotLocation.getCurrentLocation();
      Dimension size = maze.getSize();
      if ( (direction == Direction.North) && (here.getY() != 1))
      {
         neighbor = MazeCell.valueOf(here.getX(), here.getY() - 1);
      }
      else if ( (direction == Direction.South) && (here.getY() != size.getHeight()))
      {
         neighbor = MazeCell.valueOf(here.getX(), here.getY() + 1);
      }
      else if ( (direction == Direction.East) && (here.getX() != size.getWidth()))
      {
         neighbor = MazeCell.valueOf(here.getX() + 1, here.getY());
      }
      else if ( (direction == Direction.West) && (here.getX() != 1))
      {
         neighbor = MazeCell.valueOf(here.getX() - 1, here.getY());
      }
      else
      {
         return false;
      }
View Full Code Here

   /**
    * Returns the explored flag of the given location's neighbor.
    */
   private boolean getNeighborExplored(MazeCell here, Direction direction)
   {
      MazeCell neighbor;
      Dimension size = maze.getSize();
      if ( (direction == Direction.North) && (here.getY() != 1))
      {
         neighbor = MazeCell.valueOf(here.getX(), here.getY() - 1);
      }
View Full Code Here

    * MazeCell. This algorithm biases in the following order: Straight, North,
    * East, West, South
    */
   private Direction getBestDirection()
   {
      MazeCell here = robotLocation.getCurrentLocation();
      Direction current = robotLocation.getDirection();
      //int bestDistance = getDistance(here);
      Direction bestDirection = null;

      if (hasSameDirection(here, Direction2.getDirection(current)))
View Full Code Here

    * Returns the distance of the MazeCell adjacent to the passed MazeCell and
    * is adjacent in the specified direction.
    */
   private int getNeighborDistance(MazeCell here, Direction direction)
   {
      MazeCell neighbor;
      Dimension size = maze.getSize();
      if ( (direction == Direction.North) && (here.getY() != 1))
      {
         neighbor = MazeCell.valueOf(here.getX(), here.getY() - 1);
      }
View Full Code Here

   private void floodfill()
   {
      Dimension size = maze.getSize();
      Vector<MazeCell> queue = new Vector<MazeCell>();
      MazeCell cell;
      int currentDistance;
      boolean speedy;

      for (int i = 1; i <= size.width; i++)
      {
         for (int j = 1; j <= size.height; j++)
         {
            MazeCell here = MazeCell.valueOf(i, j);
            setDistance(here, USELESS);
            setDirection(here, 0);
         }
      }

      if (goal == TO_START)
      {
         cell = MazeCell.valueOf(1, size.height);
         setDistance(cell, 0);
         queue.add(cell);
         speedy = false;
      }
      else
      {
         int targetX = size.width / 2;
         int targetY = size.height / 2;
         cell = MazeCell.valueOf(targetX, targetY);
         setDistance(cell, 0);
         queue.add(cell);
         cell = MazeCell.valueOf(targetX + 1, targetY);
         setDistance(cell, 0);
         queue.add(cell);
         cell = MazeCell.valueOf(targetX, targetY + 1);
         setDistance(cell, 0);
         queue.add(cell);
         cell = MazeCell.valueOf(targetX + 1, targetY + 1);
         setDistance(cell, 0);
         queue.add(cell);
         if ( (speedRun == true) && (speedRunCapable == true))
         {
            speedy = true;
         }
         else
         {
            speedy = false;
         }
      }

      while (queue.isEmpty() == false)
      {
         cell = queue.get(0);
         queue.remove(0);
         currentDistance = getDistance(cell);

         //Check to see if accessible
         if (maze.getWall(cell, Direction.North).isSet() == false)
         { //Check to see if it should be added to queue
            if ( ( (currentDistance + 1) < getNeighborDistance(cell, Direction.North)) &&
                ( (speedy == false) || (getNeighborExplored(cell, Direction.North) == true)))
            {
               queue.add(cell.plusY(-1));
               setDistance(cell.plusY(-1), currentDistance + 1);
               setDirection(cell.plusY(-1), Direction2.South.getIndex());
            }
            else if ( ( (currentDistance + 1) == getNeighborDistance(cell, Direction.North)) &&
                     ( (speedy == false) || (getNeighborExplored(cell, Direction.North) == true)))
            {
               setDirection(cell.plusY(-1), Direction2.South.getIndex() +
                                            getDirection(cell.plusY(-1)));
            }
         }

         //Check to see if accessible
         if (maze.getWall(cell, Direction.South).isSet() == false)
         { //Check to see if it should be added to queue
            if ( ( (currentDistance + 1) < getNeighborDistance(cell, Direction.South)) &&
                ( (speedy == false) || (getNeighborExplored(cell, Direction.South))))
            {
               queue.add(cell.plusY(1));
               setDistance(cell.plusY(1), currentDistance + 1);
               setDirection(cell.plusY(1), Direction2.North.getIndex());
            }
            else if ( ( (currentDistance + 1) == getNeighborDistance(cell, Direction.South)) &&
                     ( (speedy == false) || (getNeighborExplored(cell, Direction.South) == true)))
            {
               setDirection(cell.plusY(1), Direction2.North.getIndex() +
                                           getDirection(cell.plusY(1)));
            }
         }

         //Check to see if accessible
         if (maze.getWall(cell, Direction.West).isSet() == false)
         { //Check to see if it should be added to queue
            if ( ( (currentDistance + 1) < getNeighborDistance(cell, Direction.West)) &&
                ( (speedy == false) || (getNeighborExplored(cell, Direction.West))))
            {
               queue.add(cell.plusX(-1));
               setDistance(cell.plusX(-1), currentDistance + 1);
               setDirection(cell.plusX(-1), Direction2.East.getIndex());
            }
            else if ( ( (currentDistance + 1) == getNeighborDistance(cell, Direction.West)) &&
                     ( (speedy == false) || (getNeighborExplored(cell, Direction.West) == true)))
            {
               setDirection(cell.plusX(-1), Direction2.East.getIndex() +
                                            getDirection(cell.plusX(-1)));
            }

         }

         //Check to see if accessible
         if (maze.getWall(cell, Direction.East).isSet() == false)
         { //Check to see if it should be added to queue
            if ( ( (currentDistance + 1) < getNeighborDistance(cell, Direction.East)) &&
                ( (speedy == false) || (getNeighborExplored(cell, Direction.East))))
            {
               queue.add(cell.plusX(1));
               setDistance(cell.plusX(1), currentDistance + 1);
               setDirection(cell.plusX(1), Direction2.West.getIndex());
            }
            else if ( ( (currentDistance + 1) == getNeighborDistance(cell, Direction.East)) &&
                     ( (speedy == false) || (getNeighborExplored(cell, Direction.East) == true)))
            {
               setDirection(cell.plusX(1), Direction2.West.getIndex() + getDirection(cell.plusX(1)));
            }
         }
      }

      MazeCell here = robotLocation.getCurrentLocation();
      if (getDistance(here) == USELESS)
      {
         System.out.println("Purging Knowledge");
         maze.clearMaze();
         speedRunCapable = false;
         for (int i = 0; i < size.width; i++)
         {
            for (int j = 0; j < size.height; j++)
            {
               explored[i][j] = false;
            }
         }
         explored[here.getX() - 1][here.getY() - 1] = true;
         checkWalls();
         floodfill();
      }
   }
View Full Code Here

    * 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

    * 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

Related Classes of 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.