Package kakuro.table

Examples of kakuro.table.Position


      }
    }
    Iterator<Position> it = blacks.iterator();
    it = blacks.iterator();
    while (it.hasNext()) {
      Position p = it.next();
      weights[p.x][p.y] = 0;
    }
    return weights;
  }
View Full Code Here


        if (w>9) {
              int[][] row = new int[9][1];
              for (int l=0; l<9; l++) row[l][0] = mx[i-9+l][j];
              int sum = getSum(row);
              int rnd = _random.nextInt(sum);
              Position p = getPos(row, rnd);
              //System.out.println("RandomH: "+p);
              return new Position(i-9+p.x, j);
        }
      }
    }
    for (int i=0; i<mx.length; i++) {
      for (int j=0, w=0; j<mx[0].length; j++) {
        if (mx[i][j]!=0) w++;
        else w = 0;
        if (w>9) {
              //return new Position(i, j-_random.nextInt(9));
              int[][] row = new int[9][1];
              for (int l=0; l<9; l++) row[l][0] = mx[i][j-9+l];
              int sum = getSum(row);
              int rnd = _random.nextInt(sum);
              Position p = getPos(row, rnd);
              //System.out.println("RandomV: "+p);
              return new Position(i, j-9+p.x);
        }
      }
    }
    return null;
  }
View Full Code Here

        int total = mx[0].length*mx.length;
        total -= blacks.size();
        HashSet<Position> marked = new HashSet<Position>();
    for (int j=0; j<mx[0].length; j++) {
      for (int i=0; i<mx.length; i++) {
        if (blacks.contains(new Position(i, j))) continue;
        int visited = dfs(mx, marked, i, j);
        if (visited!=total) return false;
        return true;
      }
    }
View Full Code Here

   * @param x kiinduló x pozíció
   * @param y kiinduló y pozíció
   * @return meglátogatt mezők száma, beleértve saját magát is
   * */
  protected int dfs(int[][] mx, HashSet<Position> marked, int x, int y) {
        Position p = new Position(x, y);
        if (marked.contains(p)) return 0;
        if (x<0 || y<0 || x>=mx.length || y>=mx[0].length) return 0;
        if (mx[x][y]==0) return 0;
        int result = 1;
        marked.add(p);
View Full Code Here

   * @param blacks fekete mezők
   * @param x kiinduló x
   * @param y kiinduló y koordináta
   * */
  protected void fillOneways(LinkedHashSet<Position> blacks, int x, int y) {
        Position oneway = null;
        while ((oneway = getFirstOneway(blacks, x, y))!=null) blacks.add(oneway);
  }
View Full Code Here

   * */
  protected Position getFirstOneway(LinkedHashSet<Position> blacks, int x, int y) {
        int c = 0;
        for (int j=0; j<y; j++) {
              for (int i=0; i<x; i++) {
                    if (blacks.contains(new Position(i, j))) continue;
                    c = 0;
                    if (blacks.contains(new Position(i, j+1)))  c++;
                    if (blacks.contains(new Position(i, j-1)))  c++;
                    if (blacks.contains(new Position(i+1, j)))  c++;
                    if (blacks.contains(new Position(i-1, j)))  c++;
                    if (c==3) return new Position(i, j);
                    if ((i==0 || j==0 || i==x-1 || j==y-1) && c==2) return new Position(i, j);
                    if (c==1 && (i+j==0 || i+j==x+y-2 || (i==0 && j==y-1) || (i==x-1 && j==0))) return new Position(i, j);
              }
        }
        return null;
  }
View Full Code Here

    private HashMap<Position, Boolean> _blacks = new HashMap<Position, Boolean>();
   
    /** Letárolja a kapott paramétereket, és feltölti a fekete-mapet. */
    public MySkeletonImpl(int x, int y, List<Position> list, int diff) {
      _diff = diff;
      _bounds = new Position(x, y);
      for (int i=0; i<list.size(); i++)
        _blacks.put(list.get(i), true);
    }
View Full Code Here

          }
        }
      }
      for (int i=0; i<cols; i++) {
        for (int j=0; j<rows; j++) {
          Position p = new Position(i, j);
          if (_matrix[i][j]>0) {
            _cellMap.put(p, new WhiteCell(p, _matrix[i][j], (user==null?0:user[i][j])));
          } else {
            _cellMap.put(p, new BlackCell(p, hSums[i][j], vSums[i][j]));
          }
View Full Code Here

   * @return kész-e a tábla
   * */
  public boolean isReady() throws TableException {
    for (int j=0; j<_matrix[0].length; j++) {
          for (int i=0; i<_matrix.length; i++) {
                Position p = new Position(i, j);
                boolean r = true;
                int type = getType(p);
                switch (type) {
                  case ITable.WHITE:
                  case ITable.BLACK_NONE:
View Full Code Here

   * @return jó-e a szó
   * */
  private boolean checkVertical(Position p) throws TableException {
        int sum = getSum(p, ITable.SUM_VERTICAL);
        for (int j=p.y+1; j<_matrix[0].length; j++) {
              int type = getType(new Position(p.x, j));
              if (type!=ITable.WHITE) break;
              int value = readCell(new Position(p.x, j), ITable.VALUE_NORMAL);
              if (value<1) return false;
              sum -= value;
        }
        return sum==0;
  }
View Full Code Here

TOP

Related Classes of kakuro.table.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.