Skip to content

Commit

Permalink
slither: Add Full Loop variant
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep committed Jan 15, 2025
1 parent 885d293 commit 11b8781
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src-ui/js/ui/MenuConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
case "bdwalk":
idname = "bdwalk_height";
break;
case "slither":
case "tslither":
case "swslither":
case "myopia":
case "lineofsight":
idname = "slither_full";
break;
}

if (typeof idname === "string") {
Expand Down
6 changes: 6 additions & 0 deletions src-ui/p.html
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ <h2 id="title2">読み込み中です...</h2>
<span>__heyapin_overlap__</span>
</label>
</div>
<div class="config" data-config="slither_full">
<label>
<input type="checkbox">
<span>__slither_full__</span>
</label>
</div>
<div class="config" data-config="variant">
<label>
<input type="checkbox">
Expand Down
1 change: 1 addition & 0 deletions src-ui/res/p.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@
"akichi_maximum": "Maximum numbers may be reduced",
"magnets_anti": "Anti-Magnets (adjacent poles of different magnets must be equal)",
"heyapin_overlap": "Pins must overlap 2 or more regions",
"slither_full": "All points must be visited",
"variant": "This puzzle uses variant rules",
"time": "Time:",
"timer.menu": "Show timer",
Expand Down
14 changes: 14 additions & 0 deletions src/puzzle/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
variant: true,
volatile: true
}); /* heyapin: Pins must overlap at least 2 regions */
this.add("slither_full", false, {
variant: true,
volatile: true
}); /* All vertices must be visited */
/* generic variant */
this.add("variant", false, { variant: true, volatile: true });
this.add("variantid", "", { volatile: true });
Expand Down Expand Up @@ -467,6 +471,16 @@
case "heyapin_overlap":
exec = pid === "heyapin";
break;
case "slither_full":
exec =
[
"slither",
"tslither",
"swslither",
"myopia",
"lineofsight"
].indexOf(pid) >= 0;
break;
default:
exec = !!this.list[name];
}
Expand Down
1 change: 1 addition & 0 deletions src/res/failcode.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
"cuRoomGt.akichi": "A cluster of unshaded cells is larger than the number.",
"cuRoomLt.akichi": "All clusters of unshaded cells are smaller than the number.",
"cxAdjacent.crossstitch": "Crossings are adjacent.",
"cxNoLine": "A point is not visited.",
"cxOverlap.heyapin": "A pin overlaps a single region.",
"exMinusNe.magnets": "The number of Minus signs in the row or column is not correct.",
"exNoMatch.nonogram": "The shaded cells don't match the clues in the row or column.",
Expand Down
12 changes: 10 additions & 2 deletions src/variety-common/Answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,12 @@ pzpr.classmgr.makeCommon({
this.checkLineCount(1, "lnDeadEnd");
},
checkNoLine: function() {
this.checkLineCount(0, "ceNoLine");
this.checkLineCount(0, this.board.borderAsLine ? "cxNoLine" : "ceNoLine");
},
checkNoLineIfVariant: function() {
if (this.puzzle.getConfig("slither_full")) {
this.checkNoLine();
}
},
checkLineCount: function(val, code) {
var result = true,
Expand All @@ -422,7 +427,10 @@ pzpr.classmgr.makeCommon({
if (this.checkOnly) {
break;
}
cross.seterr(1);

if (val === 0) {
cross.seterr(1);
}
bd.borderinside(
cross.bx - 1,
cross.by - 1,
Expand Down
19 changes: 19 additions & 0 deletions src/variety-common/Graphic.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ pzpr.classmgr.makeCommon({
//---------------------------------------------------------------------------
// pc.drawCrosses() Crossの丸数字をCanvasに書き込む
// pc.drawCrossMarks() Cross上の黒点をCanvasに書き込む
// pc.drawCrossErrors() Cross error dots
//---------------------------------------------------------------------------
drawCrosses: function() {
var g = this.vinc("cross_base", "auto", true);
Expand Down Expand Up @@ -969,6 +970,24 @@ pzpr.classmgr.makeCommon({
}
}
},
drawCrossErrors: function(isdraw) {
var g = this.vinc("cross_error", "auto");
g.strokeStyle = this.errcolor1;
g.lineWidth = Math.max(this.cw * 0.04, 1);

var size = this.cw / 4;
var clist = this.range.crosses;
for (var i = 0; i < clist.length; i++) {
var cross = clist[i];
g.vid = "x_ce_" + cross.id;
if (cross.error) {
g.fillStyle = cross.lcnt === 2 ? this.errbcolor1 : "white";
g.shapeCircle(cross.bx * this.bw, cross.by * this.bh, size / 2);
} else {
g.vhide();
}
}
},

//---------------------------------------------------------------------------
// pc.drawBorders() 境界線をCanvasに書き込む
Expand Down
6 changes: 6 additions & 0 deletions src/variety/lineofsight.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
this.drawBGCells();
this.drawLines();
this.drawBaseMarks();
this.drawCrossErrors();
this.drawArrowNumbers();
this.drawPekes();
this.drawTarget();
Expand All @@ -95,18 +96,22 @@
Encode: {
decodePzpr: function(type) {
this.decodeArrowNumber16();
this.puzzle.setConfig("slither_full", this.checkpflag("f"));
},
encodePzpr: function(type) {
this.outpflag = this.puzzle.getConfig("slither_full") ? "f" : null;
this.encodeArrowNumber16();
}
},
//---------------------------------------------------------
FileIO: {
decodeData: function() {
this.decodeConfigFlag("f", "slither_full");
this.decodeCellDirecQnum();
this.decodeBorderLine();
},
encodeData: function() {
this.encodeConfigFlag("f", "slither_full");
this.encodeCellDirecQnum();
this.encodeBorderLine();
}
Expand All @@ -125,6 +130,7 @@

"checkOneLoop",
"checkDeadendLine+",
"checkNoLineIfVariant",
"checkNumberHasArrow"
],

Expand Down
19 changes: 0 additions & 19 deletions src/variety/lither.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,6 @@
this.range.crosses = blist.crossinside();
this.drawBaseMarks();
this.drawCrossErrors();
},

drawCrossErrors: function(isdraw) {
var g = this.vinc("cross_error", "auto");
g.strokeStyle = this.errcolor1;
g.lineWidth = Math.max(this.cw * 0.04, 1);

var size = this.cw / 4;
var clist = this.range.crosses;
for (var i = 0; i < clist.length; i++) {
var cross = clist[i];
g.vid = "x_ce_" + cross.id;
if (cross.error) {
g.fillStyle = cross.lcnt === 2 ? this.errbcolor1 : "white";
g.shapeCircle(cross.bx * this.bw, cross.by * this.bh, size / 2);
} else {
g.vhide();
}
}
}
},

Expand Down
8 changes: 7 additions & 1 deletion src/variety/myopia.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@
this.drawBGCells();
this.drawLines();
this.drawBaseMarks();
this.drawCrossErrors();
this.drawArrowCombinations();
this.drawHatenas();
this.drawPekes();
Expand Down Expand Up @@ -313,19 +314,23 @@
Encode: {
decodePzpr: function(type) {
this.decodeNumber16();
this.puzzle.setConfig("slither_full", this.checkpflag("f"));
},
encodePzpr: function(type) {
this.outpflag = this.puzzle.getConfig("slither_full") ? "f" : null;
this.encodeNumber16();
}
},

FileIO: {
decodeData: function() {
this.decodeConfigFlag("f", "slither_full");
this.decodeCellQnum();
this.decodeCellQsub();
this.decodeBorderLine();
},
encodeData: function() {
this.encodeConfigFlag("f", "slither_full");
this.encodeCellQnum();
this.encodeCellQsub();
this.encodeBorderLine();
Expand All @@ -340,7 +345,8 @@
"checkLineDirCloser",
"checkLineDirUnequal",
"checkDeadendLine+",
"checkOneLoop"
"checkOneLoop",
"checkNoLineIfVariant"
],

getLineDirs: function() {
Expand Down
8 changes: 8 additions & 0 deletions src/variety/slither.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
if (this.pid === "swslither") {
this.drawSheepWolf();
}
this.drawCrossErrors();
this.drawQuesNumbers();
this.drawPekes();
this.drawTarget();
Expand Down Expand Up @@ -261,8 +262,10 @@
Encode: {
decodePzpr: function(type) {
this.decode4Cell();
this.puzzle.setConfig("slither_full", this.checkpflag("f"));
},
encodePzpr: function(type) {
this.outpflag = this.puzzle.getConfig("slither_full") ? "f" : null;
this.encode4Cell();
},

Expand All @@ -276,14 +279,17 @@
"Encode@swslither": {
decodePzpr: function(type) {
this.decodeNumber10();
this.puzzle.setConfig("slither_full", this.checkpflag("f"));
},
encodePzpr: function(type) {
this.outpflag = this.puzzle.getConfig("slither_full") ? "f" : null;
this.encodeNumber10();
}
},
//---------------------------------------------------------
FileIO: {
decodeData: function() {
this.decodeConfigFlag("f", "slither_full");
if (this.filever === 1) {
this.decodeCellQnum();
this.decodeCellQsub();
Expand All @@ -295,6 +301,7 @@
},
encodeData: function() {
this.filever = 1;
this.encodeConfigFlag("f", "slither_full");
this.encodeCellQnum();
this.encodeCellQsub();
this.encodeBorderLine();
Expand Down Expand Up @@ -399,6 +406,7 @@

"checkOneLoop",
"checkDeadendLine+",
"checkNoLineIfVariant",

"checkSheepIn@swslither",
"checkWolvesOut@swslither"
Expand Down
8 changes: 7 additions & 1 deletion src/variety/vslither.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
this.drawBGCells();
this.drawLines();
this.drawBaseMarks();
this.drawCrossErrors();
this.drawQuesNumbers();
this.drawPekes();
this.drawDots();
Expand Down Expand Up @@ -251,14 +252,17 @@
Encode: {
decodePzpr: function(type) {
this.decode4Cell();
this.puzzle.setConfig("slither_full", this.checkpflag("f"));
},
encodePzpr: function(type) {
this.outpflag = this.puzzle.getConfig("slither_full") ? "f" : null;
this.encode4Cell();
}
},
//---------------------------------------------------------
FileIO: {
decodeData: function() {
this.decodeConfigFlag("f", "slither_full");
this.decodeCellQnum();
this.decodeCellQsub();
this.decodeBorderLine();
Expand All @@ -267,6 +271,7 @@
});
},
encodeData: function() {
this.encodeConfigFlag("f", "slither_full");
this.encodeCellQnum();
this.encodeCellQsub();
this.encodeBorderLine();
Expand All @@ -286,7 +291,8 @@
"checkdir4VertexLine@vslither",
"checkdir4TouchLine@tslither",
"checkOneLoop",
"checkDeadendLine+"
"checkDeadendLine+",
"checkNoLineIfVariant@tslither"
],

checkdir4VertexLine: function() {
Expand Down
10 changes: 10 additions & 0 deletions test/script/slither.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ ui.debug.addDebugData("slither", {
"lnDeadEnd",
"pzprv3/slither/5/5/2 . . 1 . /. 2 . . 1 /. . 2 . . /3 . . 3 . /. 0 . . 3 /1 0 0 0 0 0 /1 1 0 1 0 0 /1 1 1 0 0 1 /1 1 1 1 1 1 /0 0 0 0 1 1 /1 1 1 1 0 /0 1 1 0 0 /0 0 1 0 1 /0 0 0 1 0 /1 0 1 0 0 /0 0 0 0 1 /"
],
[
"cxNoLine",
"pzprv3.1/slither/2/3/f/. . . /. . . /0 0 0 /0 0 0 /1 0 0 1 /1 1 0 0 /1 1 1 /0 1 1 /1 0 0 /",
{ skiprules: true }
],
[
null,
"pzprv3.1/slither/2/3/f/. . . /. . . /0 0 0 /0 0 0 /1 0 0 1 /1 1 1 1 /1 1 1 /0 1 0 /1 0 1 /",
{ skiprules: true }
],
[
null,
"pzprv3/slither/5/5/2 . . 1 . /. 2 . . 1 /. . 2 . . /3 . . 3 . /. 0 . . 3 /1 -1 0 -1 -1 1 /1 1 -1 1 -1 1 /1 1 1 0 0 1 /1 1 1 1 1 1 /-1 -1 -1 0 1 1 /1 1 1 1 1 /-1 1 1 -1 -1 /0 -1 1 0 0 /0 0 0 1 0 /1 -1 1 -1 0 /-1 0 -1 0 1 /"
Expand Down

0 comments on commit 11b8781

Please sign in to comment.