Ejemplo n.º 1
0
 public static void testBroken() {
   int[][] s = {
     {1, 0, 0, 0},
     {1, 1, 1, 0},
     {1, 1, 1, 1}
   };
   Robot r = TestHelper.makeBot(s);
   ExpandAll e = new ExpandAll(r);
   TestHelper.runMove(e);
   r.drawUnit();
 }
Ejemplo n.º 2
0
  /**
   * Instantiates a wall class on a robot with a wall that can move in a direction
   *
   * @param r the Robot on which the wall will be setup
   * @param dir the Direction the wall can move
   */
  public Wall(Robot r, int dir) {
    this.dir = dir;
    this.isDirVertical = Direction.isVertical(dir);

    // 2D arrays are width height
    Module[][] moduleArray = r.toModuleArray();
    // TODO check which is first
    w = getWidth(moduleArray);
    h = getHeight(moduleArray);
    // there will always be something in every row and every column
    // therefore we only need to look in the final column
    switch (dir) {
      case 0:
      case 2:
        level = h;
        break;
      case 1:
      case 3:
        level = w;
        break;
      default:
        /*                throw new RuntimeException("Invalid Wall direction");*/
        break;
    }
    /* TODO possibly duplicate code */
    int size = isDirVertical ? w : h;
    wallModules = new Module[size];
    isMoving = new Boolean[size];
  }
Ejemplo n.º 3
0
  public static void testMove(int w, int h) {
    int[][] start = new int[h][w];
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        start[i][j] = 1;
      }
    }

    int[][] finish = new int[w][h];
    for (int i = 0; i < w; i++) {
      for (int j = 0; j < h; j++) {
        finish[i][j] = 1;
      }
    }

    Robot r = TestHelper.makeBot(start);
    Staircase s = new Staircase(r, r.toModuleArray()[0][0], h, w);
    TestHelper.runAndDisplayMove(s);
    TestHelper.validateOutput(r, TestHelper.makeBot(finish));
  }
Ejemplo n.º 4
0
  /**
   * Updates the robot by moving the wall down and recalculating Wall
   *
   * @param r Robot which wall is in
   * @return True if update was successful
   */
  public boolean update(Robot r) {
    Module[][] moduleArray = r.toModuleArray();
    w = getWidth(moduleArray);
    h = getHeight(moduleArray);

    int size = isDirVertical ? w : h;
    wallModules = new Module[size];
    isMoving = new Boolean[size];

    level--;
    populateWall(moduleArray); // populates module Array
    markMoving(isFinalEdge()); // populates ismoving

    return true;
  }