samedi 27 juin 2015

Stop execution for a sec

I have coded N-Queen problem using backtracking in javascript.

what I want to do?

I want to spot execution of script for a second every time it reaches to solution.

what is the problem?

code execution is so fast that i can not see any color transition.

here is a part of my code (where i want to spot execution of script for a second). for full code please refer to http://ift.tt/1HmOkxV

function placeQueen(row){
    for(var i=0;i<N && row<N;i++){
      chess[row][i] = 1;
      var temp = row*N+i+1;
      //place a Queen (red color)
      $('#'+temp).css("background-color","red");
      //check if place is safe
      if(check(row,i)){
        if(row==N-1){
           //place is safe and it is last row then
           //solution found 
           //stop execution for a second 
           //then continue
           print();
        }
        else{
          placeQueen(row+1);
        }
      }
      //remove the Queen (backtracking)
      $('#'+temp).css("background-color","blue");
      chess[row][i]=0;
    }
} 

Red color : queen is placed on the box blue color : box is empty

Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire