js的数独局面生成算法,借鉴了网上的回溯法,出了问题,求助 
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css" media="all">
.text_n{
   width:50px;
   height:50px;}
</style>
<script type="text/javascript">
Shudo = function(size) {
this.size = size;
this.version = 'v1.0';
};Shudo.prototype={
answer:  [],
 num:    [1,2,3,4,5,6,7,8,9],
getAnswer:function(){
this.num.sort(function(){ return Math.random()>0.5?-1:1; });
for(var i=0;i<9;i++){
this.answer[i]=new Array;}
for(var i=0;i<9;i++){
this.answer[0][i]=this.num[i];}
for(i=1;i<9;i++){
for(j=0;j<9;j++){
this.num.sort(function(){ return Math.random()>0.5?-1:1; });
for(k=0;k<9;k++){
this.answer[i][j]=this.num[k];
var r=this.checkR(i);
var c=this.checkC(j);
var a=this.checkA(i,j);
    if(r&&c&&a){break;}
else if(k==8){
if(j>0){j-=2;}else{i--;j=8;}

}
}
}
}
//alert(this.answer);
   
},
checkR:function(row){
 var rowB=true;
               for(var j = 0;j < 8;j++){
                     for(var k =j + 1;k< 9;k++){
                              if(this.answer[row][j]!=undefined){
  if(this.answer[row][k]!=undefined){
  if(this.answer[row][j]==this.answer[row][k])
                                         rowB=false;
                                       }
                                    }
 }
                }
               return rowB;
},
checkC:function(col){
var colB=true;
               for(var j = 0;j < 8;j++){
                     for(var k =j + 1;k< 9;k++){
                              if(this.answer[j][col]!=undefined){
  if(this.answer[k][col]!=undefined){
  if(this.answer[j][col]==this.answer[k][col])
                                         colB=false;
                                       }
                                    }
 }
                }
               return colB;
},
checkA:function(row,col){
 var areaB=true;
   //获得左上角的坐标
   var r=Math.floor(row/3)*3;
   var c=Math.floor(col/3)*3;
   var a=[];
               for(var i=0;i<8;i++){
   for(var j=i+1;j<9;j++){
   if(this.answer[r+Math.floor(i/3)][c+i%3]!=undefined){
   if(this.answer[r+Math.floor(j/3)][c+j%3]!=undefined){
   if(this.answer[r+Math.floor(i/3)][c+i%3]==this.answer[r+Math.floor(j/3)][c+j%3])
   areaB=false;
   }
   }
   }
   }
                 return areaB;
}
}
window.onload=function(){
var shudo=new Shudo(9);
shudo.getAnswer();
//alert(shudo.answer);
}}
</script>