首页 > 代码库 > 数独助手

数独助手

<script type="text/javascript">// > (v%3);}Pos.prototype.checkFix = function(){ var count = 0; var pos=-1; var i; for(i=0; i<3; i++) { if(this.pbit[i]!=0) { count ++; pos = i; } } if(count == 0) { alert("invalid " + this.x + " " + this.y); return 0; } if(count>1) return 0; if(this.pbit[pos] == 4 || this.pbit[pos] == 2 || this.pbit[pos] == 1) { this.fixValue = http://www.mamicode.com/pos*3 + (this.pbit[pos]==4?0:(this.pbit[pos]==2?1:2)) + 1;>> (v%3)); return this.checkFix();}Pos.prototype.text = function(line, col){ if(this.pbit[line] & (4 >> col)) { var v = (line*3 + col + 1).toString();; return "
" + v + "
"; } return "";}Pos.prototype.drawTd = function(v){ var td = ""; td += ""; td += v; td += ""; return td;}Pos.prototype.draw = function(){ var html = "";; html += "
"; if(this.fixValue) { var tableClass = "fix"; if(this.error) tableClass = "err"; html += ""; html += "" + this.drawTd("") + this.drawTd("") + this.drawTd("") + ""; html += "" + this.drawTd("") + this.drawTd(this.fixValue) + this.drawTd("") + ""; html += "" + this.drawTd("") + this.drawTd("") + this.drawTd("") + ""; html += "
"; } else { html += ""; for(i=0; i<3; i++) { html += ""; for(j=0; j<3; j++) html += this.drawTd(this.text(i, j)) html += ""; } html += "
"; } html += "
" return html;}function Rect9(obj){ this.obj = obj; this.p = []; var i; var j; for(i=0; i< 9; i++) { this.p[i] = new Array(); for(j=0; j< 9; j++) { this.p[i][j] = new Pos(i, j); } }}Rect9.prototype.clear = function(){ var i; var j; for(i=0; i< 9; i++) { for(j=0; j< 9; j++) { this.p[i][j].clear(); } }}Rect9.prototype.value = http://www.mamicode.com/function(x, y)""; for(i=0; i<9; i++) { html += ""; for(j=0; j<9; j++) { html += ""; } html += ""; } html += "
"; html += this.p[i][j].draw(); html += "
"; this.obj.innerHTML = html;}function setValue(x, y, v){ var newFixCount = 0; r.setValue(x, y, v); newFixCount = r.unsetValue(x, y, v); while(newFixCount>0) { newFixCount = 0; var i, j; for(i=0; i<9; i++) for(j=0; j<9; j++) { if(r.isNewFix(i,j)) newFixCount += r.unsetValue(i, j, r.value(i,j)); } }}var xStack = [];var yStack = [];var vStack = [];function clickValue(x, y, v){ xStack.push(x); yStack.push(y); vStack.push(v); setValue(x, y, v); r.draw();}function undoClick(){ r.clear(); xStack.pop(); yStack.pop(); vStack.pop(); var i; for(i=0; i</script><style></style>

<script type="text/javascript">// </script>