예제 #1
0
파일: Tabuleiro.java 프로젝트: mh3ry/lleme
  private static List<Pos> emTorno(Pos p, Pos exclusao) {
    List<Pos> pes = new ArrayList<>();
    Pos pe;
    if (p != null && p.i >= 0 && p.i < estado.length && p.j >= 0 && p.j < estado[0].length) {

      pe = new Pos(p.i - 1, p.j);
      if (pe.i >= 0
          && pe.i < estado.length
          && pe.j >= 0
          && pe.j < estado[0].length
          && !pe.equals(exclusao)) pes.add(pe);

      pe = new Pos(p.i, p.j - 1);
      if (pe.i >= 0
          && pe.i < estado.length
          && pe.j >= 0
          && pe.j < estado[0].length
          && !pe.equals(exclusao)) pes.add(pe);

      pe = new Pos(p.i + 1, p.j);
      if (pe.i >= 0
          && pe.i < estado.length
          && pe.j >= 0
          && pe.j < estado[0].length
          && !pe.equals(exclusao)) pes.add(pe);

      pe = new Pos(p.i, p.j + 1);
      if (pe.i >= 0
          && pe.i < estado.length
          && pe.j >= 0
          && pe.j < estado[0].length
          && !pe.equals(exclusao)) pes.add(pe);
    }
    return pes;
  }
예제 #2
0
 public Pos getSecondNearestNode(Pos p) {
   Pos nearest = getNearestNode(p);
   int nearestRow = getRow(nearest);
   int nearestCol = getCol(nearest);
   if (nearest.equals(p)) return null;
   if (nearest.x == p.x) {
     if (nearest.y < p.y) return createPosFromNode(nearestRow + 1, nearestCol);
     else return createPosFromNode(nearestRow - 1, nearestCol);
   } else /* if (nearest.y == p.y) */ {
     if (nearest.x < p.x) return createPosFromNode(nearestRow, nearestCol + 1);
     else return createPosFromNode(nearestRow, nearestCol - 1);
   }
 }
예제 #3
0
 public Pos getNearestNode(Pos p) {
   int row = getRow(p);
   int col = getCol(p);
   Pos nearest = createPosFromNode(row, col);
   double minDist = p.dist(nearest);
   if (nearest.equals(p)) return p;
   Pos tmp;
   if (nearest.x == p.x) {
     tmp = createPosFromNode(row + 1, col);
   } else /* if (nearest.y == p.y) */ {
     tmp = createPosFromNode(row, col + 1);
   }
   if (p.dist(tmp) < minDist) nearest = tmp;
   return nearest;
 }
예제 #4
0
파일: Tabuleiro.java 프로젝트: mh3ry/lleme
 private static int contaZeroEmTorno(Pos p, Pos exclusao) {
   int cont = 0;
   for (Pos pe : emTorno(p, null)) if (!pe.equals(exclusao) && estado[pe.i][pe.j] == 0) cont++;
   return cont;
 }