1
0

Fixed twoValPlaces check. Added more logging.

This commit is contained in:
Markus Birth 2014-01-25 18:58:34 +01:00
parent 235916e588
commit cc35969757
4 changed files with 17 additions and 9 deletions

View File

@ -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

View File

@ -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()

View File

@ -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);
}
}
}

View File

@ -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();