Fixed twoValPlaces check. Added more logging.
This commit is contained in:
parent
235916e588
commit
cc35969757
@ -56,16 +56,20 @@ class @SudokuChecks
|
||||
p = (1 << i) | (1 << j)
|
||||
console.log('Now checking (%o, %o) mask: %o', i+1, j+1, p)
|
||||
for k of cells
|
||||
if cells[k].getValue() is '.' and cells[k].getMask() & p is p
|
||||
if cells[k].getValue() is '.' and (cells[k].getMask() & p) is p
|
||||
n++
|
||||
console.log('%d: %d, %d (%o, %o)', n, p, cells[k].getMask(), (p & cells[k].getMask()), ((p & cells[k].getMask()) is p))
|
||||
console.info('Have %d matches.', n) if n > 0
|
||||
if n is 2
|
||||
console.warn('Two matches!')
|
||||
for k of cells
|
||||
if cells[k].getValue() is '.' and cells[k].getMask() is p
|
||||
if cells[k].getValue() is '.' and (cells[k].getMask() & p) is p
|
||||
cells[k].setMask(p)
|
||||
else if cells[k].getValue() is '.'
|
||||
cells[k].setMask(cells[k].getMask() & ~p)
|
||||
curMask = cells[k].getMask()
|
||||
console.log('Current Mask: %o', curMask)
|
||||
newMask = curMask & ~p
|
||||
console.log('New Mask: %o', newMask)
|
||||
cells[k].setMask(newMask)
|
||||
console.groupEnd()
|
||||
return true
|
||||
|
@ -95,7 +95,7 @@ class @SudokuSolver
|
||||
@[c](board)
|
||||
break if board.hasChanged()
|
||||
if board.hasChanged()
|
||||
console.info('Board was changed by "%s".', description)
|
||||
console.info('%i. Board was changed by "%s".', i, description)
|
||||
body = document.getElementsByTagName('body')
|
||||
body[0].innerHTML += i + '. ' + description + '<br />'
|
||||
board.print()
|
||||
|
@ -70,7 +70,7 @@
|
||||
};
|
||||
|
||||
SudokuChecks.twoValPlaces = function(cells) {
|
||||
var dim2, i, j, k, n, p, _i, _j, _ref, _ref1;
|
||||
var curMask, dim2, i, j, k, n, newMask, p, _i, _j, _ref, _ref1;
|
||||
if (!cells[0]) {
|
||||
return;
|
||||
}
|
||||
@ -82,7 +82,7 @@
|
||||
p = (1 << i) | (1 << j);
|
||||
console.log('Now checking (%o, %o) mask: %o', i + 1, j + 1, p);
|
||||
for (k in cells) {
|
||||
if (cells[k].getValue() === '.' && cells[k].getMask() & p === p) {
|
||||
if (cells[k].getValue() === '.' && (cells[k].getMask() & p) === p) {
|
||||
n++;
|
||||
console.log('%d: %d, %d (%o, %o)', n, p, cells[k].getMask(), p & cells[k].getMask(), (p & cells[k].getMask()) === p);
|
||||
}
|
||||
@ -93,10 +93,14 @@
|
||||
if (n === 2) {
|
||||
console.warn('Two matches!');
|
||||
for (k in cells) {
|
||||
if (cells[k].getValue() === '.' && cells[k].getMask() === p) {
|
||||
if (cells[k].getValue() === '.' && (cells[k].getMask() & p) === p) {
|
||||
cells[k].setMask(p);
|
||||
} else if (cells[k].getValue() === '.') {
|
||||
cells[k].setMask(cells[k].getMask() & ~p);
|
||||
curMask = cells[k].getMask();
|
||||
console.log('Current Mask: %o', curMask);
|
||||
newMask = curMask & ~p;
|
||||
console.log('New Mask: %o', newMask);
|
||||
cells[k].setMask(newMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -165,7 +165,7 @@
|
||||
}
|
||||
}
|
||||
if (board.hasChanged()) {
|
||||
console.info('Board was changed by "%s".', description);
|
||||
console.info('%i. Board was changed by "%s".', i, description);
|
||||
body = document.getElementsByTagName('body');
|
||||
body[0].innerHTML += i + '. ' + description + '<br />';
|
||||
board.print();
|
||||
|
Reference in New Issue
Block a user