Fixed twoValPlaces check. Added more logging.
This commit is contained in:
@ -56,16 +56,20 @@ class @SudokuChecks
|
|||||||
p = (1 << i) | (1 << j)
|
p = (1 << i) | (1 << j)
|
||||||
console.log('Now checking (%o, %o) mask: %o', i+1, j+1, p)
|
console.log('Now checking (%o, %o) mask: %o', i+1, j+1, p)
|
||||||
for k of cells
|
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++
|
n++
|
||||||
console.log('%d: %d, %d (%o, %o)', n, p, cells[k].getMask(), (p & cells[k].getMask()), ((p & cells[k].getMask()) is p))
|
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
|
console.info('Have %d matches.', n) if n > 0
|
||||||
if n is 2
|
if n is 2
|
||||||
console.warn('Two matches!')
|
console.warn('Two matches!')
|
||||||
for k of cells
|
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)
|
cells[k].setMask(p)
|
||||||
else if cells[k].getValue() is '.'
|
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()
|
console.groupEnd()
|
||||||
return true
|
return true
|
||||||
|
@ -95,7 +95,7 @@ class @SudokuSolver
|
|||||||
@[c](board)
|
@[c](board)
|
||||||
break if board.hasChanged()
|
break if board.hasChanged()
|
||||||
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 = document.getElementsByTagName('body')
|
||||||
body[0].innerHTML += i + '. ' + description + '<br />'
|
body[0].innerHTML += i + '. ' + description + '<br />'
|
||||||
board.print()
|
board.print()
|
||||||
|
@ -70,7 +70,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
SudokuChecks.twoValPlaces = function(cells) {
|
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]) {
|
if (!cells[0]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@
|
|||||||
p = (1 << i) | (1 << j);
|
p = (1 << i) | (1 << j);
|
||||||
console.log('Now checking (%o, %o) mask: %o', i + 1, j + 1, p);
|
console.log('Now checking (%o, %o) mask: %o', i + 1, j + 1, p);
|
||||||
for (k in cells) {
|
for (k in cells) {
|
||||||
if (cells[k].getValue() === '.' && cells[k].getMask() & p === p) {
|
if (cells[k].getValue() === '.' && (cells[k].getMask() & p) === p) {
|
||||||
n++;
|
n++;
|
||||||
console.log('%d: %d, %d (%o, %o)', n, p, cells[k].getMask(), p & cells[k].getMask(), (p & cells[k].getMask()) === p);
|
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) {
|
if (n === 2) {
|
||||||
console.warn('Two matches!');
|
console.warn('Two matches!');
|
||||||
for (k in cells) {
|
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);
|
cells[k].setMask(p);
|
||||||
} else if (cells[k].getValue() === '.') {
|
} 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()) {
|
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 = document.getElementsByTagName('body');
|
||||||
body[0].innerHTML += i + '. ' + description + '<br />';
|
body[0].innerHTML += i + '. ' + description + '<br />';
|
||||||
board.print();
|
board.print();
|
||||||
|
Reference in New Issue
Block a user