gt:         if (r == 0)
context: package automenta.falcon.minefield;
  
  import jurls.reinforcementlearning.domains.RLEnvironment;
  
  class Maze implements RLEnvironment  {
      final int size = 16;
      final int numMines = 10;
      final boolean binarySonar = false;
  
      final int LINEAR = 0;
      final int EXP = 1;
      private final int RewardType = EXP; 
  
      private int agent_num;
  
      private int[][] current;
      private int[][] prev_current;
      private int[] target;
      private int[] currentBearing;
      private int[] prev_bearing;
      private int[] targetBearing;
      private double[][] sonar;
      private double[][] av_sonar;
      private int[] range;
      private int[][] mines;
  
      private int[][] avs;
      private boolean[] end_state;
      private boolean[] conflict_state;
  
      public Maze(int ag_num) {
          refreshMaze(ag_num);
      }
  
      public void set_conflict(int i, int j) {
          avs[current[i][0]][current[i][1]] = 0;
          end_state[i] = true;
          end_state[j] = true;
          conflict_state[i] = true;
          conflict_state[j] = true;
  
  
  
  
      }
  
      public boolean check_conflict(int i) {
          int k;
  
          if ((current[i][0] == target[0]) && (current[i][1] == target[1]))
              return (false);
          if (conflict_state[i])
              return (true);
          if ((current[i][0] < 0) || (current[i][1] < 0))
              return (false);
          for (k = 0; k < agent_num; k++) {
              if (k == i)
                  continue;
              if ((current[k][0] == current[i][0]) && (current[k][1] == current[i][1])) {
                  set_conflict(i, k);
                  return (true);
              }
          }
          return (false);
      }
  
      public boolean check_conflict(int agt, int pos[], boolean actual) {
          int k;
  
          for (k = 0; k < agent_num; k++) {
              if (k == agt)
                  continue;
              if ((current[k][0] == pos[0]) && (current[k][1] == pos[1])) {
                  if (actual) {
                      set_conflict(agt, k);
                  }
                  return (true);
              }
          }
          return (false);
      }
  
      public void refreshMaze(int agt) {
          int k, w;
          int x, y;
          double d;
  
          
          if (agt < 1)
              agent_num = 1;
          else if (agt > 10)
              agent_num = 10;
          else
              agent_num = agt;
          current = new int[agent_num][];
          target = new int[2];
          prev_current = new int[agent_num][];
          currentBearing = new int[agent_num];
          prev_bearing = new int[agent_num];
          targetBearing = new int[agent_num];
          avs = new int[size][size];
          mines = new int[size][size];
          end_state = new boolean[agent_num];
          conflict_state = new boolean[agent_num];
  
          sonar = new double[agent_num][];
          av_sonar = new double[agent_num][];
  
          for (k = 0; k < agent_num; k++) {
              current[k] = new int[2];
              prev_current[k] = new int[2];
              end_state[k] = false;
              conflict_state[k] = false;
              sonar[k] = new double[5];
              av_sonar[k] = new double[5];
          }
  
          for (k = 0; k < 3; k++)
              d = Math.random();
  
          for (int i = 0; i < size; i++)
              for (int j = 0; j < size; j++)
                  avs[i][j] = 0;
  
          for (k = 0; k < agent_num; k++) {
              do {
                  x = (int) (Math.random() * size);
                  current[k][0] = x;
                  y = (int) (Math.random() * size);
                  current[k][1] = y;
              }
              while (avs[x][y] > 0);
  
              avs[x][y] = k + 1;
  
              for (w = 0; w < 2; w++)
                  prev_current[k][w] = current[k][w];
  
              end_state[k] = false;
              conflict_state[k] = false;
          }
  
          do {
              x = (int) (Math.random() * size);
              target[0] = x;
              y = (int) (Math.random() * size);
              target[1] = y;
          } while (avs[x][y] > 0);
  
          for (int i = 0; i < size; i++)
              for (int j = 0; j < size; j++)
                  mines[i][j] = 0;
  
          for (int i = 0; i < numMines; i++) {
              do {
                  x = (int) (Math.random() * size);
                  y = (int) (Math.random() * size);
              }
              while ((avs[x][y] > 0) || (mines[x][y] == 1) || (x == target[0] && y == target[1]));
              mines[x][y] = 1;
          }
          for (int a = 0; a < agent_num; a++) {
              this.setCurrentBearing(a, this.adjustBearing(this.getTargetBearing(a)));
              prev_bearing[a] = this.currentBearing[a];
          }
      }
  
      public int adjustBearing(int old_bearing) {
          if ((old_bearing == 1) || (old_bearing == 7))
              return (0);
          if ((old_bearing == 3) || (old_bearing == 5))
              return (4);
          return (old_bearing);
      }
  
      public int getTargetBearing(int i) {
          if ((current[i][0] < 0) || (current[i][1] < 0))
              return (0);
          int[] d = new int[agent_num];
  
          d = new int[2];
          d[0] = target[0] - current[i][0];
          d[1] = target[1] - current[i][1];
  
          if (d[0] == 0 && d[1] < 0)
              return (0);
          if (d[0] > 0 && d[1] < 0)
              return (1);
          if (d[0] > 0 && d[1] == 0)
              return (2);
          if (d[0] > 0 && d[1] > 0)
              return (3);
          if (d[0] == 0 && d[1] > 0)
              return (4);
          if (d[0] < 0 && d[1] > 0)
              return (5);
          if (d[0] < 0 && d[1] == 0)
              return (6);
          if (d[0] < 0 && d[1] < 0)
              return (7);
          return (0);
      }
  
      public int[] getTargetBearing() {
          int[] ret = new int[agent_num];
          int k;
  
          for (k = 0; k < agent_num; k++)
              ret[k] = getTargetBearing(k);
          return (ret);
      }
  
      public int getCurrentBearing(int i) {
          return (currentBearing[i]);
      }
  
      public int[] getCurrentBearing() {
          return (currentBearing);
      }
  
      public void setCurrentBearing(int[] b) {
          currentBearing = b;
      }
  
      public void setCurrentBearing(int i, int b) {
          currentBearing[i] = b;
      }
  
      public double getRewards(int agt, int[] pos, boolean actual, boolean immediate) {
          int x = pos[0];
          int y = pos[1];
  
          if ((x == target[0]) && (y == target[1])) 
          {
              end_state[agt] = true;
              avs[x][y] = 0;
              return (1);
          }
          if ((x < 0) || (y < 0)) 
              return (-1);
  
          if (mines[x][y] == 1)       
              return (0);
  
  
  
  
          if (immediate) {
              if (RewardType == LINEAR) {
                  int r = getRange(agt);
                  if (r > 10) r = 10;
                  return (1.0 - (double) r / 10.0); 
              } else
                  return (1.0 / (double) (1 + getRange(agt))); 
          }
          return 0.0; 
      }
  
      public double getRewards(int i, boolean immediate) {
          return (getRewards(i, current[i], true, immediate));
      }
  
      public double[] getRewards(boolean immediate) {
          int k;
          double[] r;
  
          r = new double[agent_num];
          for (k = 0; k < agent_num; k++) {
              r[k] = getRewards(k, immediate);
          }
          return (r);
      }
  
      public int getRange(int[] a, int[] b) {
          int range;
          int[] d = new int[2];
  
          d[0] = Math.abs(a[0] - b[0]);
          d[1] = Math.abs(a[1] - b[1]);
          range = Math.max(d[0], d[1]);
          return (range);
      }
  
      public int getRange(int i) {
          return (getRange(current[i], target));
      }
  
      public int getRange(int i, int j) {
          return (getRange(current[i], current[j]));
      }
  
      public int[] getRange() {
          int k;
          int[] range;
  
          range = new int[agent_num];
          for (k = 0; k < agent_num; k++) {
              range[k] = getRange(k);
          }
          return (range);
      }
  
      public double getTargetRange(int i) {
          return 1.0 / (double) (1 + getRange(i));
      }
  
      public double[] getTargetRange() {
          int k;
          double[] range;
  
          range = new double[agent_num];
          for (k = 0; k < agent_num; k++) {
              range[k] = getTargetRange(k);
          }
          return (range);
      }
  
      public void getSonar(int agt, double[] new_sonar) {
          int r;
          int x = current[agt][0];
          int y = current[agt][1];
  
          if ((x < 0) || (y < 0)) {
              for (int k = 0; k < 5; k++)
                  new_sonar[k] = 0;
              return;
          }
  
          double[] aSonar = new double[8];
  
          r = 0;
          while (y - r >= 0 && mines[x][y - r] != 1)
              r++;
          if (r == 0)
              aSonar[0] = 0.0;
          else
              aSonar[0] = 1.0 / (double) r;
  
          r = 0;
          while (x + r <= size - 1 && y - r >= 0 && mines[x + r][y - r] != 1)
              r++;
          if (r == 0)
              aSonar[1] = 0.0;
          else
              aSonar[1] = 1.0 / (double) r;
  
          r = 0;
          while (x + r <= size - 1 && mines[x + r][y] != 1)
              r++;
          if (r == 0)
              aSonar[2] = 0.0;
          else
              aSonar[2] = 1.0 / (double) r;
  
          r = 0;
          while (x + r <= size - 1 && y + r <= size - 1 && mines[x + r][y + r] != 1)
              r++;
  