// File: Moor.java
// Time-stamp: "2005-01-06 19:04:27 calvanese"
// Scopo: representation of a moor
//        used for the traversal problem


public class Moor {

  private boolean[][] moor;

  public Moor(int rows, int columns, double probLand) {
    moor = new boolean[rows][columns];
    for (int r = 0; r < rows; r++)
      for (int c = 0; c < columns; c++)
        moor[r][c] = (Math.random() < probLand);
  }

  public int getNumRows() {
    return moor.length;
  }

  public int getNumColumns() {
    return moor[0].length;
  }

  public boolean land(int r, int c) {
    return (r >= 0) && (r < moor.length) &&
      (c >= 0) && (c < moor[0].length) &&
      moor[r][c];
  }

  public String toString() {
    String res = "";
    for (int r = 0; r < moor.length; r++) {
      for (int c = 0; c < moor[0].length; c++)
        res = res + (moor[r][c]? "*" : "o");
      res = res + "\n";
    }
    return res;
  }
}
