Skip to content

Commit

Permalink
kinkonkan: Add check for unused mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep committed Sep 16, 2023
1 parent 0bd7f09 commit d2756a1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/res/failcode.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"ceSuspend.view": "There is a cell that is not filled in number.",
"ceTapaNe.tapa": "The number is not equal to the length of surrounding shaded cells.",
"ceTooManyBlocks.doppelblock": "There are more than two blocks in a row or column.",
"ceUnused.kinkonkan": "A mirror is unused.",
"ciNotOnCnr.loute": "A circle is not at the corner of an area.",
"circleNotPromontory.kurodoko": "A circle is not a dead end.",
"circleShade": "A white circle is shaded.",
Expand Down
28 changes: 22 additions & 6 deletions src/variety/kinkonkan.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,13 @@
this.haslight = false;
this.puzzle.redraw();
},
searchLight: function(startexcell, setlight) {
var ccnt = 0,
searchLight: function(startexcell, setlight, ldata) {
var ccnt = 0;
if (!ldata) {
ldata = [];
for (var c = 0; c < this.cell.length; c++) {
ldata[c] = 0;
for (var c = 0; c < this.cell.length; c++) {
ldata[c] = 0;
}
}

var pos = startexcell.getaddr(),
Expand Down Expand Up @@ -676,7 +678,8 @@
"checkSingleMirrorInRoom",
"checkPairMirror",
"checkReflectionCount",
"checkExistMirrorInRoom"
"checkExistMirrorInRoom",
"checkMirrorUnused"
],

checkSingleMirrorInRoom: function() {
Expand Down Expand Up @@ -711,6 +714,7 @@
this.checkMirrors(2, "pairedNumberNe");
},
checkMirrors: function(type, code) {
var ldata = [];
var d = [],
bd = this.board,
result = true,
Expand All @@ -720,7 +724,7 @@
if (!isNaN(d[ec]) || excell.qnum === -1 || excell.qchar === 0) {
continue;
}
var ret = bd.searchLight(excell, false),
var ret = bd.searchLight(excell, false, ldata),
excell2 = bd.excell[ret.dest];
if (
(type === 1 && excell.qchar !== excell2.qchar) ||
Expand All @@ -741,12 +745,24 @@
d[ec] = 1;
d[ret.dest] = 1;
}
if (result || !this.checkOnly) {
this._info.ldata = ldata;
}
if (!result) {
this.failcode.add(code);
if (errorExCell) {
bd.searchLight(errorExCell, true);
}
}
},
checkMirrorUnused: function() {
if (!this._info.ldata) {
this.checkMirrors();
}
var ldata = this._info.ldata;
this.checkAllCell(function(cell) {
return cell.qans && !ldata[cell.id];
}, "ceUnused");
}
}
});
7 changes: 6 additions & 1 deletion test/script/kinkonkan.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ ui.debug.addDebugData("kinkonkan", {
"bkNoObj",
"pzprv3/kinkonkan/4/4/6/0 0 1 2 /3 3 1 2 /3 3 4 4 /5 5 4 4 /. 2,2 1,1 . 4,1 . /3,2 . . . . . /. . . . . 1,1 /. . . . . . /3,2 . . . . 4,1 /. . . 2,2 . . /1 + 1 + /+ 1 + + /+ + + + /2 + + 1 /"
],
[
"ceUnused",
"pzprv3.1/kinkonkan/3/3/4/0 0 1 /2 1 1 /3 3 1 /. . . . . /1,2 1 . 1 . /1,2 2 . . 2,2 /. 1 . . 2,2 /. . . . . /"
],

// large number bug
[
null,
"pzprv3.1/kinkonkan/3/3/9/0 1 2 /3 4 5 /6 7 8 /. . . . . /1,10 1 2 1 . /1,10 1 2 2 2,3 /. 1 2 2 . /. . 2,3 . . /"
"pzprv3.1/kinkonkan/3/3/9/0 1 2 /3 4 5 /6 7 8 /. . . . . /1,10 1 2 1 . /1,10 1 2 2 2,3 /. 1 2 2 . /. . 2,3 . . /",
{ skiprules: true }
],

[
Expand Down

1 comment on commit d2756a1

@vercel
Copy link

@vercel vercel bot commented on d2756a1 Sep 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pzprjs – ./

pzprjs-git-main-robx.vercel.app
pzprjs.vercel.app
pzprjs-robx.vercel.app

Please sign in to comment.