Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Sudoku Backtracking Slowed Down

$
0
0
hello, i would like to slow down this backtracking solution by using Thread.sleep(1000);
but with my code it only waits 1000 at the beginning of the method and then suddenly it is solved.
i want it to wait 1000 after every solving try.
this is my code:
public void solve( int row, int col ) throws Exception
   {
      int updater3 = 0;
      if( row > 8 ){
        //Gelöst
        for (int i= 0;i<9;i++){    
             for(int j=0;j<9;j++){
                 System.out.print(sudo2[i][j]+" ");
                    if (j==8){
                        System.out.println();
                    }
                    button[updater3].setText(String.valueOf(sudo2[i][j]));
                    updater3=updater3+1;
                    if (updater3 >= 80){
                        updater3 = 0;
                    }
                }
      }
      }
      // wenn die Stelle belegt ist, mit der nächsten weitermachen
      if( sudo2[row][col] != 0 ){
         next( row, col ) ;
        }
      else
      {
         // Eine mögliche Nummer für diesen Button finden
         for( int num = 1; num < 10; num++ )
         {
            if( checkHorizontal(row,num) == false && checkVertikal(col,num)== false&& checkBox(row,col,num)== false )
            {
                for (int i= 0;i<9;i++){    
             for(int j=0;j<9;j++){
                 System.out.print(sudo2[i][j]+" ");
                    if (j==8){
                        System.out.println();
                    }
                    button[updater3].setText(String.valueOf(sudo2[i][j]));
                    updater3=updater3+1;
                    if (updater3 >= 80){
                        updater3 = 0;
                    }
                }
      }
               sudo2[row][col] = num ;
               //Updating the Buttons
                for (int i= 0;i<9;i++){    
             for(int j=0;j<9;j++){
                 System.out.print(sudo2[i][j]+" ");
                    if (j==8){
                        System.out.println();
                    }
                    button[updater3].setText(String.valueOf(sudo2[i][j]));
                    updater3=updater3+1;
                    if (updater3 >= 80){
                        updater3 = 0;
                    }
                }
      }
                

               //Geschwindigkeit des Lösens einstellen
               Thread.sleep( geschwindigkeit2 ) ; //Noch verbessern
               //Updating the buttons
               for (int i= 0;i<9;i++){    
             for(int j=0;j<9;j++){
                 System.out.print(sudo2[i][j]+" ");
                    if (j==8){
                        System.out.println();
                    }
                    button[updater3].setText(String.valueOf(sudo2[i][j]));
                    updater3=updater3+1;
                    if (updater3 >= 80){
                        updater3 = 0;
                    }
                }
      }

               //next row and next col
               next( row, col ) ;
            }
         }


The system.out.print works and it updates the console like i want it but my buttons where the sudoku should be displayed isnt updating

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>