Package kakuro.table

Examples of kakuro.table.Position


   *
   * @return cellák listája
   * */
  protected ArrayList<Position> createListForPositions(int x1,int y1, int x2, int y2){
    ArrayList<Position> list = new ArrayList<Position>();
    Position _p_f;
    for(int m = x1;m <= x2; m++){
      for(int n = y1;n <= y2; n++){
        _p_f = new Position(m,n);
        list.add(_p_f);
      }
    }
    return list;
  }
View Full Code Here


   
    /* Eloszor osszegyujtom egy matrixba a fekete-feher ertekeket, 1, ha fekete,
     * ebbol varazsolom ki a graf csomopontjait majd   */
    for (int y=0; y<sorokszama; y++) {
      for (int x=0; x<oszlopokszama; x++) {
        int celltipus = skeleton.getType(new Position(x, y));
        bwMatrix[x][y] = (celltipus==ISkeletonTable.CELL_BLACK?1:0);
      }
    }
    print(bwMatrix, "bwMatrix");
   
    /* Eloallitom a vizszintes szavakat tartalmazo matrixot, a szavakat megszamozom 1-tol */
    int hcounter = 1;
    boolean inword = false;
    HashMap<Integer, Integer> hCount = new HashMap<Integer, Integer>();
    for (int y=0; y<sorokszama; y++) {
      for (int x=0; x<oszlopokszama; x++) {
            if (bwMatrix[x][y]==0) {
                  horizontalWords[x][y] = hcounter;
                  inword = true;
                  hCount.put(hcounter, hcounter);
            } else {
                  if (inword) hcounter++;
                  inword = false;
            }
      }
    }
    print(horizontalWords, "horizontal words");
   
    /* Ugyanez, csak fuggolegesre is. itt meg annyit csinalok, hogy lementem egy mapbe azt, hogy
     * egy adott fuggoleges es vizszintes szo metszetehez, ami ugye valojaban egy cella az eredeti
     * tablaban, pontosan milyen Position is tartozik. igy tehat a graf egy elehez majd siman meg tudom
     * mondani, hogy az valojaban melyik cella volt. */
    int vcounter = 1;
    inword = false;
    HashMap<Integer, Integer> vCount = new HashMap<Integer, Integer>();
    HashMap<Position, Position> wordToCellMap = new HashMap<Position, Position>();
    for (int x=0; x<oszlopokszama; x++) {
          for (int y=0; y<sorokszama; y++) {
            if (bwMatrix[x][y]==0) {
                  verticalWords[x][y] = vcounter;
                  inword = true;
                  vCount.put(vcounter, vcounter);
                  wordToCellMap.put(new Position(horizontalWords[x][y], vcounter), new Position(x, y));
            } else {
                  if (inword) vcounter++;
                  inword = false;
            }
      }
    }
    print(verticalWords, "vertical words");
   
    /* Fo ciklus. Az innerCycle fuggveny egy maximalis (maximum!) parositast ad vissza. Ezt elmentem, kiosztom az
     * eleknek egy szamot, es a kovetkezo korben kiveszem a generalasbol ezeket az eleket - erre szolgal az exclusions
     * map.  */
    ArrayList<Position> maximumMatching = null;
    HashMap<Position, Boolean> exclusions = new HashMap<Position, Boolean>();
    int run = 0;
    int[] statistics = new int[10];
    do {
          maximumMatching = innerCycle(sorokszama, oszlopokszama, hCount.size(), vCount.size(), bwMatrix, horizontalWords, verticalWords, wordToCellMap, exclusions, run);
          statistics[run] = maximumMatching.size();
          run++;
          for (int i=0; i<maximumMatching.size(); i++) {
                exclusions.put(maximumMatching.get(i), true);
                Position p = wordToCellMap.get(maximumMatching.get(i));
                result[p.x][p.y] = run;
          }
    } while ((maximumMatching.size()>0) && (run<9));
   
    HashMap<Position, Boolean> problematicEdgesMap = new HashMap<Position, Boolean>();
    Iterator<Position> it = wordToCellMap.keySet().iterator();
    while (it.hasNext()) {
          Position e = it.next();
          if (!exclusions.containsKey(e)) problematicEdgesMap.put(e, true);
    }
   
    /* problemas elek a 9-dik futas utan: ezek azok az elek a grafban, ahol nem tudott a moho algoritmus szint kiosztani
     * ezekre javito ut kell */
    Iterator<Position> problematicEdges = problematicEdgesMap.keySet().iterator();
    while (problematicEdges.hasNext()) {
        statistics[9]++;
          Position edge = problematicEdges.next();
          int[] freeColors = getFreeColors(edge, wordToCellMap, hCount.size(), vCount.size(), result);
          System.out.println("Left out: "+edge+", free colors: "+freeColors[0]+" - "+freeColors[1]);
          Position p = wordToCellMap.get(edge);
              result[p.x][p.y] = freeColors[0];
          Position next = edge;
          HashMap<Position, Boolean> visited = new HashMap<Position, Boolean>();
          boolean horizontalToVertical = false;
          while ((next = getNextEnRoute(next, freeColors[0], freeColors[1], wordToCellMap, result, hCount.size(), vCount.size(), horizontalToVertical, visited))!=null) {
                //invertColors(next, freeColors[0], freeColors[1], wordToCellMap, result);
                horizontalToVertical ^= true;
View Full Code Here

        System.out.println("keresem a kovetkezojet: "+current+" irany: "+horizontalToVertical+", szinek: "+color1+"-"+color2);
        visited.put(current, true);
        if (!horizontalToVertical) {
              int vWord = current.y;
              for (int i=1; i<=hCount; i++) {
                  if (visited.containsKey(new Position(i, vWord))) continue;
                    if (wordToCellMap.containsKey(new Position(i, vWord))) {
                          Position actual = wordToCellMap.get(new Position(i, vWord));
                          int color = colors[actual.x][actual.y];
                          System.out.println("\ttalaltam elet "+new Position(i, vWord)+" -> "+actual+", szine: "+color);
                          if (color==color1) {
                                colors[actual.x][actual.y] = color2;
                                return new Position(i, vWord);
                          }
                    }
              }
        } else {
              int hWord = current.x;
              for (int i=1; i<=vCount; i++) {
                  if (visited.containsKey(new Position(hWord, i))) continue;
                    if (wordToCellMap.containsKey(new Position(hWord, i))) {
                          Position actual = wordToCellMap.get(new Position(hWord, i));
                          int color = colors[actual.x][actual.y];
                          if (color==color2) {
                                colors[actual.x][actual.y] = color1;
                                return new Position(hWord, i);
                          }
                    }
              }
        }
        return null;
View Full Code Here

        int vWord = e.y;
        int[] result = new int[2];
        result[0] = result[1] = -1;
        boolean[] used = new boolean[10];
        for (int i=1; i<=vCount; i++) {
              if (wordToCellMap.containsKey(new Position(hWord, i))) {
                    Position actual = wordToCellMap.get(new Position(hWord, i));
                    if (colors[actual.x][actual.y]>0) used[colors[actual.x][actual.y]] = true;
              }
        }
        result[0] = getFirst(used);
        used = new boolean[10];
        for (int i=1; i<=hCount; i++) {
              if (wordToCellMap.containsKey(new Position(i, vWord))) {
                    Position actual = wordToCellMap.get(new Position(i, vWord));
                    if (colors[actual.x][actual.y]>0) used[colors[actual.x][actual.y]] = true;
              }
        }
        result[1] = getFirst(used);
        return result;
View Full Code Here

    for (int y=0; y<sorokszama; y++) {
      for (int x=0; x<oszlopokszama; x++) {
            if (bwMatrix[x][y]==1) continue;
            int hWordId = horizontalWords[x][y];
            int vWordId = verticalWords[x][y];
            if (exclusions.containsKey(new Position(hWordId, vWordId))) {
                  continue;
            }
            neighbours.get(hWordId).add(vWordId);
      }
    }
    for (int i=0; i<neighbours.size(); i++) Collections.shuffle(neighbours.get(i));
    System.out.println("vCount: "+vCount+", hCount: "+hCount);
   
    /* minden vizszintes szora lefuttatom a melysegi keresest */
    int[] markedNodes = new int[Math.max(vCount, hCount)+1];
    int[] visitedNodes = new int[Math.max(vCount, hCount)+1];
    boolean[] visited = new boolean[hCount];
    for (int i=1; i<=hCount; i++) {
        int j = nextFree(visited)+1;
        //System.out.println("Doing run j "+j);
          depthFirstSearch(neighbours, markedNodes, visitedNodes, j, j);
    }
   
    /* es visszaadom az eredmenyt */
    int all = 0;
    for (int i=1; i<=vCount; i++) {
          all += (markedNodes[i] != 0)?1:0;
          if (markedNodes[i]!=0) {
                System.out.println("Run "+run+", found edge "+markedNodes[i]+"--->"+i+" : "+wordToCellMap.get(new Position(markedNodes[i], i)));
                result.add(new Position(markedNodes[i], i));
          }
    }
    System.out.println("all: "+all);
    return result;
  }
View Full Code Here

        break;
    }
   
    List<Position> result = makeSkeleton(x-1, y-1);
    translate(result);
    for (int i=0; i<x; i++result.add(new Position(i, 0));
    for (int i=0; i<y; i++result.add(new Position(0, i));
      return new MySkeletonImpl(x, y, result, skillLevel);
  }
View Full Code Here

 
  /** Eggyel eltolja a kapott pozíciókat jobbra és lefele. Azért van szükség erre, mert így egyszerűbben
   * biztosítható az, hogy a bal és a felső sor mindig fekete maradjon. */
  protected void translate(List<Position> list) {
    for (int i=0; i<list.size(); i++) {
      Position p = list.get(i);
      list.set(i, new Position(p.x+1, p.y+1));
    }
  }
View Full Code Here

  /** Skeleton gyártó főfüggvény, megkapja a tábla kiterjedését, és visszaadja a feketék helyét listában. */ 
  protected List<Position> makeSkeleton(int x, int y) {
    LinkedHashSet<Position> blacks = new LinkedHashSet<Position>();
    int[][] weights = fillWeights(blacks, x, y);
    int counter = 0;
    Position longPos = null;
    int rollbackCounter = 0;
    int[] rollbackStat = new int[3];
    while ((counter<((x*y)/10)) || (longPos = checkLongs(weights))!=null) {
          if (rollbackCounter>11) {
                //System.out.println("Rollback3333");
                rollbackCounter = 0;
                rollbackStat[0]++;
                Iterator<Position> it = blacks.iterator();
                Position p1 = null;
                Position p2 = null;
                while (it.hasNext()) {
                      p1 = p2;
                      p2 = it.next();
                }
                blacks.remove(p1);
                blacks.remove(p2);
                weights = fillWeights(blacks, x, y);
                continue;
          }
      if (counter>((x*y)/10)) {
        blacks.add(longPos);
        weights = fillWeights(blacks, x, y);
        if (!checkTree(weights, blacks)) {
          //System.out.println("rollback1!");
          rollbackCounter++;
          rollbackStat[1]++;
          blacks.remove(longPos);
          weights = fillWeights(blacks, x, y);
        }
        continue;
      }
      int rnd = _random.nextInt(getSum(weights));
      Position nextBlack = getPos(weights, rnd);
      blacks.add(nextBlack);
      weights = fillWeights(blacks, x, y);
      if (!checkTree(weights, blacks)) {
        //System.out.println("rollback2!");
        rollbackCounter++;
View Full Code Here

  protected Position getPos(int[][] mx, int sum) {
    for (int j=0; j<mx[0].length; j++) {
      for (int i=0; i<mx.length; i++) {
        if (mx[i][j]==0) continue;
        sum -= mx[i][j];
        if (sum<1) return new Position(i, j);
      }
    }
    return null;
  }
View Full Code Here

  protected int getBlackNeighbourCount(HashSet<Position> blacks, int x, int y, int mx, int my) {
        int result = 0;
        for (int i=-1; i<2; i++) {
              for (int j=-1; j<2; j++) {
                    if (x+i<0 || y+j<0 || x+i>=mx || y+j>=my) continue;
                    result += (blacks.contains(new Position(x+i, y+j))?1:0);
              }
        }
        return result;
  }
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.