Examples of MazeCell


Examples of maze.model.MazeCell

      {
         //Goals are not poisoned
         return false;
      }

      MazeCell here;
      Direction whereFrom = dir.getOpposite();

      if (dir.equals(Direction.North))
      {
         here = cell.plusY(-1);
View Full Code Here

Examples of maze.model.MazeCell

    */
   public RobotController(MazeModel model, RobotBase robotAI)
   {
      this.mazeModel = model;
      this.ai = robotAI;
      final MazeCell start = MazeCell.valueOf(1, this.mazeModel.getSize().height);
      this.robotModelMaster = new RobotModelMaster(this.mazeModel, start, Direction.North);
      this.robotModelClient = new RobotModel(this.robotModelMaster);
      this.initialize();
   }
View Full Code Here

Examples of maze.model.MazeCell

    */
   private Direction getNeighborDirection(Direction direction)
   {
      try
      {
         final MazeCell there = robotLocation.getCurrentLocation().neighbor(direction);
         if (!there.isInRange(robotLocation.getMazeSize()))
            return null;
         else
            return this.getDirection(there);
      }
      catch (IllegalArgumentException e)
View Full Code Here

Examples of maze.model.MazeCell

    * This sets the direction for the understanding for the current cell.
    */
   private void setDirection()
   {
      Direction wayBack = robotLocation.getDirection().getOpposite();
      MazeCell here = robotLocation.getCurrentLocation();
      ballOfString[here.getX() - 1][here.getY() - 1] = wayBack;
   }
View Full Code Here

Examples of maze.model.MazeCell

    * 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

Examples of maze.model.MazeCell

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

Examples of maze.model.MazeCell

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

      if ( (bestDistance > getNeighborDistance(here, robotLocation.getDirection())) &&
          (robotLocation.isWallFront() == false))
View Full Code Here

Examples of maze.model.MazeCell

    * 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

Examples of maze.model.MazeCell

   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++)
         {
            setDistance(MazeCell.valueOf(i, j), USELESS);
         }
      }

      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);
            }
         }

         //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);
            }
         }

         //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);
            }
         }

         //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);
            }
         }

      }

      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

Examples of maze.model.MazeCell

    * Draws the arrows and numbers on the maze.
    * @param g What to draw on.
    */
   private void drawUnderstanding(final Graphics2D g)
   {
      MazeCell here;
      if (understandingInt != null)
      {
         int local;
         for (int i = 1; i <= model.getSize().width; i++)
         {
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.