diff --git a/src/variety/kurotto.js b/src/variety/kurotto.js index 86ca126ed..14e94d0da 100644 --- a/src/variety/kurotto.js +++ b/src/variety/kurotto.js @@ -80,7 +80,7 @@ if (!this.puzzle.execConfig("autocmp")) { return false; } - return this.checkComplete(); + return this.checkComplete() && this.checkUnambiguous(); } }, "Board@island": { @@ -88,7 +88,52 @@ this.islandgraph = this.addInfoList(this.klass.AreaIslandGraph); } }, + + "Cell@mines": { + maxnum: 8, + + checkComplete: function() { + if (!this.isValidNum()) { + return true; + } + + var cnt = 0; + var cells = [ + this.relcell(-2, -2), + this.relcell(0, -2), + this.relcell(2, -2), + this.relcell(-2, 0), + this.relcell(2, 0), + this.relcell(-2, 2), + this.relcell(0, 2), + this.relcell(2, 2) + ]; + for (var i = 0; i < 8; i++) { + if ( + cells[i].group === "cell" && + !cells[i].isnull && + cells[i].isShade() + ) { + cnt++; + } + } + return this.qnum === cnt; + }, + + checkUnambiguous: function() { + return true; + } + }, + "Cell@kurotto,island": { + allowShade: function() { + return !(this.isValidNum() || this.qnum === -2); + }, + + allowUnshade: function() { + return !(this.isValidNum() || this.qnum === -2); + }, + maxnum: function() { var max = this.board.cell.length - 1; return max <= 999 ? max : 999; @@ -118,37 +163,32 @@ } } return this.qnum === cnt; - } - }, - "Cell@mines": { - maxnum: 8, + }, - checkComplete: function() { + checkUnambiguous: function() { if (!this.isValidNum()) { return true; } - - var cnt = 0; - var cells = [ - this.relcell(-2, -2), - this.relcell(0, -2), - this.relcell(2, -2), - this.relcell(-2, 0), - this.relcell(2, 0), - this.relcell(-2, 2), - this.relcell(0, 2), - this.relcell(2, 2) - ]; - for (var i = 0; i < 8; i++) { - if ( - cells[i].group === "cell" && - !cells[i].isnull && - cells[i].isShade() - ) { - cnt++; + var cellsAndAdjacent = new Set(); + var list = this.getdir4clist(); + for (var i = 0; i < list.length; i++) { + var area = list[i][0].sblk; + if (area !== null) { + for (var j = 0; j < area.clist.length; j++) { + var sublist = area.clist[j].getdir4clist(); + for (var k = 0; k < sublist.length; k++) { + cellsAndAdjacent.add(sublist[k][0]); + } + } } } - return this.qnum === cnt; + var satisfied = true; + cellsAndAdjacent.forEach(function(cell) { + if (!cell.isShadeDecided()) { + satisfied = false; + } + }); + return satisfied; } }, diff --git a/src/variety/tasquare.js b/src/variety/tasquare.js index b4a297d26..3d227f18b 100644 --- a/src/variety/tasquare.js +++ b/src/variety/tasquare.js @@ -62,7 +62,15 @@ if (!this.puzzle.execConfig("autocmp")) { return false; } - return this.checkComplete(); + return this.checkComplete() && this.checkUnambiguous(); + }, + + allowShade: function() { + return !this.isNum(); + }, + + allowUnshade: function() { + return !this.isNum(); }, checkComplete: function() { @@ -87,6 +95,32 @@ } return this.isValidNum() ? this.qnum === cnt : cnt > 0; + }, + + checkUnambiguous: function() { + if (!this.isValidNum()) { + return true; + } + var cellsAndAdjacent = new Set(); + var list = this.getdir4clist(); + for (var i = 0; i < list.length; i++) { + var area = list[i][0].sblk; + if (area !== null) { + for (var j = 0; j < area.clist.length; j++) { + var sublist = area.clist[j].getdir4clist(); + for (var k = 0; k < sublist.length; k++) { + cellsAndAdjacent.add(sublist[k][0]); + } + } + } + } + var satisfied = true; + cellsAndAdjacent.forEach(function(cell) { + if (!cell.isShadeDecided()) { + satisfied = false; + } + }); + return satisfied; } },