Package kakuro.table

Examples of kakuro.table.Position


    _difficulty = skeleton.getDifficulty();
    _blacks.clear();
    _fields.clear();
    for (int i=0; i<_x; i++)
      for (int j=0; j<_y; j++)
        if (skeleton.getType(new Position(i, j))==ISkeletonTable.CELL_BLACK)
          _blacks.put(new Position(i, j), true);
    redraw();
  }
View Full Code Here


    GridLayout layout = new GridLayout(_y, _x, 1, 1);
    setLayout(layout);
   
    for (int j = 0; j < _y; j++) {
      for (int i = 0; i < _x; i++) {
        Position pos = new Position(i, j);
        SkellyField f = new SkellyField(pos, _blacks.containsKey(pos));
        add(f);
        _fields.put(pos, f);
      }
    }
    for (int j = 0; j < _y; j++) {
      for (int i = 0; i < _x; i++) {
        Position pos = new Position(i, j);
        checkLongs(pos);
      }
    }
    validate();
    repaint();
View Full Code Here

   * @param p kiindulási pozíció
   * */
  protected void checkLongs(Position p) {
        for (int i=0; i<_x; i++) {
              for (int j=0; j<_y; j++) {
                    if (i==p.x || j==p.y) checkLongs2(new Position(i, j));
              }
        }
  }
View Full Code Here

  protected void checkLongs2(Position pos) {
        if (_blacks.containsKey(pos)) {
              _fields.get(pos).setProblematic(false);
              return;
        }
        Position p;
        int horizontalCount = 1;
        for (int i=pos.x-1; i>=0; i--) {
              p = new Position(i, pos.y);
              if (_blacks.containsKey(p)) break;
              horizontalCount++;
        }
        for (int i=pos.x+1; i<_x; i++) {
              p = new Position(i, pos.y);
              if (_blacks.containsKey(p)) break;
              horizontalCount++;
        }
        int verticalCount = 1;
        for (int i=pos.y-1; i>=0; i--) {
              p = new Position(pos.x, i);
              if (_blacks.containsKey(p)) break;
              verticalCount++;
        }
        for (int i=pos.y+1; i<_y; i++) {
              p = new Position(pos.x, i);
              if (_blacks.containsKey(p)) break;
              verticalCount++;
        }
        if (horizontalCount>9 || verticalCount>9) {
              _fields.get(pos).setProblematic(true);
View Full Code Here

    if (table.getColumnCount()!=skeleton.getColumnCount() || table.getRowCount()!=skeleton.getRowCount())
      throw new IndexOutOfBoundsException("Table size mismatch");
    showValues = true;
    for (int j=0; j<_y; j++) {
      for (int i=0; i<_x; i++) {
        Position p = new Position(i, j);
        SkellyField field = _fields.get(p);
        switch (table.getType(p)) {
          case ITable.BLACK_NONE:  field.setValues(0, 0)break;
          case ITable.BLACK_BOTH: field.setValues(table.getSum(p, ITable.SUM_HORIZONTAL), table.getSum(p, ITable.SUM_VERTICAL))break;
          case ITable.BLACK_HORIZONTAL:  field.setValues(table.getSum(p, ITable.SUM_HORIZONTAL), 0)break;
View Full Code Here

   
    for (int y=0; y<sorokszama; y++) {
      for (int x=0; x<oszlopokszama; x++) {
        positionPriority[x][y]=0;
        positionValues[x][y]=0;
        Position actual = new Position(x, y);
        int celltipus = skeleton.getType(actual);
        String tipus = (celltipus==ISkeletonTable.CELL_BLACK?"Fekete":"Feher");
        System.out.println("at ("+x+","+y+"): "+tipus);
       
       
        //  ###   poziciok prioritasanak szamolasa   ###
                
        if ( celltipus == ISkeletonTable.CELL_WHITE){
         
          int x_pos = x;
          boolean whitePos=true;
          int celltipusNext=ISkeletonTable.CELL_BLACK;
          //int celltipusNextBlack=ISkeletonTable.CELL_BLACK;
         
          positionPriority[x][y]++;
         
         
          do{
            x_pos--;
            Position nextPosition = new Position(x_pos, y);
            celltipusNext = skeleton.getType(nextPosition);
            if( celltipusNext == ISkeletonTable.CELL_WHITE )
              positionPriority[x][y]++;
            else
              whitePos = false;
          }while( whitePos == true );
         
          // ### vizszintes +   ###
          x_pos = x;
            do{
              while ( x_pos < (oszlopokszama-1) ){
                x_pos++;
                Position nextPosition = new Position(x_pos, y);
                celltipusNext = skeleton.getType(nextPosition);
                if( celltipusNext == ISkeletonTable.CELL_WHITE )
                  positionPriority[x][y]++;
                else
                  whitePos = false;
               
                if( x_pos < (oszlopokszama-1) ){
                  Position nextBlackPosition = new Position(x_pos+1, y);
                  int celltipusNextBlack = skeleton.getType(nextBlackPosition);
                  if( celltipusNextBlack == ISkeletonTable.CELL_BLACK)
                    break
                }
                if( x_pos == (oszlopokszama-1))
                  break;
             
            }while( whitePos == true );
           
            //   ### vizszintes -   ###
            x_pos=x;
            do{
              x_pos--;
              Position nextPosition = new Position(x_pos, y);
              celltipusNext = skeleton.getType(nextPosition);
              if( celltipusNext == ISkeletonTable.CELL_WHITE )
                positionPriority[x][y]++;
              else
                whitePos = false;
            }while( whitePos == true );
           
            //   ### fuggoleges +   ###
            int y_pos = y;
              do{
                while ( y_pos < (sorokszama-1) ){
                  y_pos++;
                  Position nextPosition = new Position(x, y_pos);
                  celltipusNext = skeleton.getType(nextPosition);
                  if( celltipusNext == ISkeletonTable.CELL_WHITE )
                    positionPriority[x][y]++;
                  else
                    whitePos = false;
                 
                  if( y_pos < (sorokszama-1) ){
                    Position nextBlackPosition = new Position(x, y_pos);
                    int celltipusNextBlack = skeleton.getType(nextBlackPosition);
                    if( celltipusNextBlack == ISkeletonTable.CELL_BLACK)
                      break
                  }
                  if( y_pos == (sorokszama-1))
                    break;
                }
              }while( whitePos == true );
         
              //   ### fuggoleges
              y_pos=y;
              do{
                y_pos--;
                Position nextPosition = new Position(x, y_pos);
                celltipusNext = skeleton.getType(nextPosition);
                if( celltipusNext == ISkeletonTable.CELL_WHITE )
                  positionPriority[x][y]++;
                else
                  whitePos = false;
              }while( whitePos == true );
        }
        System.out.println(" vizszintes prio szam: "+ positionPriority[x][y]);
       
        // a poziciok ertekkel valo feltoltese
       
        int i_pos, j_pos;
        for( int prioNumIdx = 16; prioNumIdx >1; prioNumIdx-- ){
          for (int j=0; j<sorokszama; j++) {
            for (int i=0; i<oszlopokszama; i++) {
              if ( positionPriority[i][j] == prioNumIdx ){
                i_pos=i;
                boolean[] values = new boolean[10]; // a lehetseges ertekek
                for ( int v=1; v<10; v++) values[v]= true;
               
                while ( positionPriority[i_pos][j] !=0 ){
                  i_pos++;
                  for (int check=0; check!=10; check++){
                    if( positionValues[i_pos][j]==checkvalues[check] = false;
                  }         
                }
               
                i_pos=i;
                while ( positionPriority[i_pos][j] !=0 ){
                  i_pos--;
                  for (int check=0; check!=10; check++){
                    if( positionValues[i_pos][j]==checkvalues[check] = false;
                  }         
                }
               
                j_pos=j;
                while ( positionPriority[i][j_pos] !=0 ){
                  j_pos++;
                  for (int check=0; check!=10; check++){
                    if( positionValues[i][j_pos]==checkvalues[check] = false;
                  }         
                }
               
                j_pos=j;
                while ( positionPriority[i][j_pos] !=0 ){
                  j_pos--;
                  for (int check=0; check!=10; check++){
                    if( positionValues[i][j_pos]==checkvalues[check] = false;
                  }         
                }
               
                int valuesCount=0;
                for (int v=0; v!=10; v++)
                  if ( values[v]==true ) valuesCount++;
               
                Random rand = new Random();
                //int n = 10;
                  //int r = rand.nextInt(n+1);
                  int r = rand.nextInt(valuesCount);
                 
                  int trueIdx=0;
                  int w=1;
                  while( w!=10 ){
                    if( values[w]==true ){
                      trueIdx++;
                      if( trueIdx==r positionValues[i][j]=w;
                    }
                    w++;
                  }
              }
              //System.out.println(i+". sor, "+j+". oszlop: "+ positionValues[i][j]);
            }
            //System.out.println(" ###### ");
          }
        }       
      }
    }
   
   
    for (int jdx=0; jdx< sorokszama; jdx++){
      int str[]=new int[oszlopokszama+1];
      for (int idx=0; idx < oszlopokszama; idx++){
        str[idx]=positionValues[idx][jdx];
        //System.out.println(positionValues[idx][jdx]);
      }
      //System.out.println(jdx+". sor: "+str[0]+str[1]+str[2]+str[3]+str[4]+str[5]+str[6]+str[7]+str[8] ); 
    }
   
//  ###########################################
   
    System.out.println("#########################");
   
    Vector<String> wordsInRows = new Vector<String>();
    Vector<String> wordsInColumns = new Vector<String>();
   
    /*for (int x=0; x!=oszlopokszama+1; x++)
      for (int y=0; y!=sorokszama+1; y++)
        positionValues[x][y]=0;*/
   
   
    for (int y=0; y!=sorokszama; y++) {
      for (int x=0; x!=oszlopokszama; x++) {
       
        Position actual = new Position(x, y);
        Position prePosition_X = new Position( x-1 , y );
        Position prePosition_Y = new Position( x , y-1 );
        int celltipus = skeleton.getType(actual);
        int celltipus_pre_X = skeleton.getType(prePosition_X);
        int celltipus_pre_Y = skeleton.getType(prePosition_Y);
        //String tipus = (celltipus==ISkeletonTable.CELL_BLACK?"Fekete":"Feher");
        //System.out.println("at ("+x+","+y+"): "+tipus);
   
       
        if ( celltipus_pre_X == ISkeletonTable.CELL_BLACK && celltipus == ISkeletonTable.CELL_WHITE ){
 
          boolean nextPositionBlack=false;
          int celltipusNext=ISkeletonTable.CELL_BLACK;
          int x_pos = x;                  // ### vizszintes   ###
          do{
              x_pos++;
                if ( x_pos == oszlopokszama){
                  String nextWord= x + "~" + (x_pos-1) + "," + y  ;
                  wordsInRows.add(nextWord);
                  nextPositionBlack = true;
                }else{
                  Position nextPosition = new Position(x_pos, y);
                  celltipusNext = skeleton.getType(nextPosition);
                  if( celltipusNext == ISkeletonTable.CELL_BLACK ) {
                    nextPositionBlack = true;
                    String nextWord= x + "~" + (x_pos-1) + "," + y  ;
                    wordsInRows.add(nextWord);
                    }
                }
            }while( nextPositionBlack != true );
        }
       
        if ( celltipus_pre_Y == ISkeletonTable.CELL_BLACK && celltipus == ISkeletonTable.CELL_WHITE ){
         
          boolean nextPositionBlack=false;
          int celltipusNext=ISkeletonTable.CELL_BLACK;
          int y_pos = y;                  // ### f�gg�leges   ###
          do{
              y_pos++;
                if ( y_pos == sorokszama){
                  String nextWord= x + "," + y + "~" + (y_pos-1) ;
                  wordsInColumns.add(nextWord);
                  nextPositionBlack = true;
                }else{
                  Position nextPosition = new Position(x, y_pos);
                  celltipusNext = skeleton.getType(nextPosition);
                  if( celltipusNext == ISkeletonTable.CELL_BLACK ) {
                    nextPositionBlack = true;
                    String nextWord= x + "," + y + "~" + (y_pos-1) ;
                    wordsInColumns.add(nextWord);
View Full Code Here

    int cols = Integer.parseInt(s[3]);
    int rows = Integer.parseInt(s[2]);
    HashMap<Position, Boolean> map = new HashMap<Position, Boolean>();
    for (int i=0; i<rows; i++) {
      for (int j=0; j<cols; j++) {
        if (s[4].charAt((i*cols)+j)=='B') map.put(new Position(j, i), true);
      }
    }
    System.out.println("loading "+rs.getInt("TableId"));
    return new SkeletonTableImpl(map, rows, cols, dif, rs.getInt("TableId"));
  }
View Full Code Here

    String content = "";
    int x = table.getColumnCount();
    int y = table.getRowCount();
    for (int j = 0; j < y; j++) {
      for (int i = 0; i < x; i++) {
        Position pos = new Position(i, j);
        switch (table.getType(pos)) {
        case ITable.BLACK_NONE:
        {
          content = content + "-|-";
          break;
View Full Code Here

    int difficulty = skeleton.getDifficulty();
    int x = skeleton.getColumnCount();
    int y = skeleton.getRowCount();
    for (int j = 0; j < y; j++) {
      for (int i = 0; i < x; i++) {
        Position pos = new Position(i, j);
        switch (skeleton.getType(pos)) {
        case ISkeletonTable.CELL_BLACK:
        {
          content = content + "B";
          break;
View Full Code Here

  /** Törli a táblát. */
  public void clear() {
    removeAll();
    for (int i = 0; i < _x; i++) {
      for (int j = 0; j < _y; j++) {
        add(new GamefieldNone(_gui, this, i + "," + j, new Position(i,
            j)));
      }
    }
    validate();
  }
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.