Пример #1
0
  @Test
  public void gridTest() {
    Grid grid = new Grid(5, 4);

    assertEquals(Color.NONE, grid.get(4, 3).get());

    grid.set(4, 3, Color.BAD);
    assertEquals(Color.BAD, grid.get(4, 3).get());

    grid.set(4, 3, Color.GOOD);
    assertEquals(Color.GOOD, grid.get(4, 3).get());
  }
Пример #2
0
  @Test
  public void setTest() {
    Grid<Integer> grid = new Grid<Integer>(4, 2, null);

    grid.set(0, 0, 1);
    grid.set(1, 0, 4);
    grid.set(3, 0, 3);

    System.out.println(grid.toString());

    assertEquals(3, (int) grid.get(3, 0));
    assertNull(grid.get(2, 0));
  }
Пример #3
0
    private Grid generateTorusGrid(
        GL gl, int uSteps, int vSteps, float majorRadius, float minorRadius) {
      Grid grid = new Grid(uSteps + 1, vSteps + 1);
      for (int j = 0; j <= vSteps; j++) {
        double angleV = Math.PI * 2 * j / vSteps;
        float cosV = (float) Math.cos(angleV);
        float sinV = (float) Math.sin(angleV);
        for (int i = 0; i <= uSteps; i++) {
          double angleU = Math.PI * 2 * i / uSteps;
          float cosU = (float) Math.cos(angleU);
          float sinU = (float) Math.sin(angleU);
          float d = majorRadius + minorRadius * cosU;
          float x = d * cosV;
          float y = d * (-sinV);
          float z = minorRadius * sinU;

          float nx = cosV * cosU;
          float ny = -sinV * cosU;
          float nz = sinU;

          float length = (float) Math.sqrt(nx * nx + ny * ny + nz * nz);
          nx /= length;
          ny /= length;
          nz /= length;

          grid.set(i, j, x, y, z, nx, ny, nz);
        }
      }
      grid.createBufferObjects(gl);
      return grid;
    }
Пример #4
0
  private static void solve(Grid grid, List<Grid> solutions) {
    // Return if there is already more than two solution
    if (solutions.size() >= 2) {
      return;
    }

    // Find first empty cell
    int loc = grid.findEmptyCell();

    // If no empty cells are found,a solution is found
    if (loc < 0) {
      solutions.add(grid.clone());
      return;
    }

    // Try each of the 9 digits in this empty cell
    for (int n = 1; n < 10; n++) {
      if (grid.set(loc, n)) {
        // With this cell set,work on the next cell
        solve(grid, solutions);

        // Clear the cell so that it can be filled with another digit
        grid.clear(loc);
      }
    }
  }
Пример #5
0
  @Test
  public void zoneTest() {
    // 1 1 2 2
    // 1 1 3 3
    // 2 2 2 2
    Grid<Integer> grid = new Grid<Integer>(4, 3, null);
    grid.set(0, 0, 1);
    grid.set(1, 0, 1);
    grid.set(2, 0, 2);
    grid.set(3, 0, 2);
    grid.set(0, 1, 1);
    grid.set(1, 1, 1);
    grid.set(2, 1, 3);
    grid.set(3, 1, 3);
    grid.set(0, 2, 2);
    grid.set(1, 2, 2);
    grid.set(2, 2, 2);
    grid.set(3, 2, 2);

    Grid<Boolean> zone = grid.zone(2, 0);
    assertTrue(zone.get(2, 0));
    assertTrue(zone.get(3, 0));
    assertEquals(2, zone.count(true));

    zone = grid.zone(0, 2);
    assertTrue(zone.get(0, 2));
    assertTrue(zone.get(1, 2));
    assertTrue(zone.get(2, 2));
    assertTrue(zone.get(3, 2));
    assertEquals(4, zone.count(true));
  }