Skip to content

Commit

Permalink
Add Turn and Run
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep committed Jan 18, 2025
1 parent 90b5474 commit bdccf7f
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 13 deletions.
1 change: 1 addition & 0 deletions src-ui/js/ui/KeyPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ ui.keypopup = {
pencils: [10, 0],
minarism: [10, 10],
trainstations: [124, 0],
turnrun: [124, 0],
wafusuma: [10, 0],
kuroclone: [10, 0],
martini: [10, 0],
Expand Down
1 change: 1 addition & 0 deletions src-ui/js/ui/MenuConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
case "ovotovata":
case "balance":
case "turnaround":
case "turnrun":
idname = "loop_full";
break;
}
Expand Down
1 change: 1 addition & 0 deletions src-ui/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ <h2 id="title"><span lang="ja">パズルの種類のリスト</span><span lang="
<li data-pid="crossstitch"></li>
<li data-pid="roundtrip"></li>
<li data-pid="trainstations"></li>
<li data-pid="turnrun"></li>
</ul>
</div>
<div class="lists loops">
Expand Down
3 changes: 2 additions & 1 deletion src/puzzle/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@
"midloop",
"ovotovata",
"balance",
"turnaround"
"turnaround",
"turnrun"
].indexOf(pid) >= 0;
break;
default:
Expand Down
1 change: 1 addition & 0 deletions src/pzpr/variety.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@
triplace: [0, 0, "トリプレイス", "Tri-place"],
tslither: [0, 0, "Touch Slitherlink", "Touch Slitherlink", "vslither"],
turnaround: [0, 0, "ターンアラウンド", "Turnaround"],
turnrun: [0, 0, "Turn and Run", "Turn and Run", "trainstations"],
twinarea: [0, 0, "ツインエリア", "Twin Area", "hanare"],
usotatami: [0, 0, "ウソタタミ", "Uso-tatami", "fillmat"],
usoone: [0, 0, "ウソワン", "Uso-one"],
Expand Down
5 changes: 3 additions & 2 deletions src/res/failcode.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
"ceDirection.compass": "The number of cells in the direction is wrong.",
"ceDirection.mukkonn": "A line that exits a cell turns at the wrong position.",
"ceDirection.guidearrow": "A cell does not follow the indicated direction towards the goal.",
"ceDirection.turnrun": "A line that exits a cell turns at the wrong position.",
"ceEmpty.kaidan": "There is an empty cell.",
"ceEmpty.lightshadow": "There is an undetermined cell.",
"ceEmpty.shugaku": "There is an empty cell.",
Expand Down Expand Up @@ -615,6 +616,7 @@
"lnSnLine.lither": "There is only one tree.",
"lnStarNe.starbattle": "The number of stars in a line is wrong.",
"lnStraightOnIce.firewalk": "A line goes straight through fire.",
"lnStraightOnNum": "A line goes straight through a number.",
"lnWrongAngle.kouchoku": "Some segments meet at the wrong angle.",
"lookairBC.lookair": "Two squares of the same size can see each other.",
"lpNoNum.onsen": "A loop has no numbers.",
Expand Down Expand Up @@ -807,8 +809,7 @@
"nonCirclePromontory.kurodoko": "A dead end has no circle.",
"nqAroundDup.kakuru": "There are same numbers around the pre-numbered cell.",
"nqAroundSumNe.kakuru": "A sum of numbers around the pre-numbered cell is incorrect.",
"numNoLine.geradeweg": "A number has no line.",
"numNoLine.turnaround": "A number has no line.",
"numNoLine": "A number has no line.",
"objShaded.nurimaze": "An object is shaded.",
"pairedLetterNe.kinkonkan": "Beam from a light doesn't reach its pair.",
"pairedNumberNe.kinkonkan": "The number of reflections is wrong.",
Expand Down
2 changes: 1 addition & 1 deletion src/res/failcode.ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
"nonCirclePromontory.kurodoko": "丸のないマスが岬になっています。",
"nqAroundDup.kakuru": "初めから出ている数字の周りに同じ数字が入っています。",
"nqAroundSumNe.kakuru": "初めから出ている数字の周りに入る数の合計が正しくありません。",
"numNoLine.geradeweg": "線の通っていない数字があります。",
"numNoLine": "線の通っていない数字があります。",
"objShaded.nurimaze": "オブジェクトが黒マスになっています。",
"pairedLetterNe.kinkonkan": "光が同じ文字の場所へ到達しません。",
"pairedNumberNe.kinkonkan": "光の反射回数が正しくありません。",
Expand Down
111 changes: 102 additions & 9 deletions src/variety/trainstations.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
} else {
pzpr.classmgr.makeCustom(pidlist, classbase);
}
})(["trainstations"], {
})(["trainstations", "turnrun"], {
MouseEvent: {
inputModes: {
edit: ["number", "undef", "empty", "clear", "info-line"],
Expand Down Expand Up @@ -74,6 +74,29 @@
return this.isEmpty();
}
},
"Cell@turnrun": {
maxnum: function() {
var bd = this.board;
return Math.max(bd.cols, bd.rows) - 1;
},
getSegmentDir: function(dir) {
var llist = new this.klass.PieceList();
var pos = this.getaddr().movedir(dir, 1);
while (1) {
var border = pos.getb();
if (!border || border.isnull) {
break;
}
if (border.isLine()) {
llist.add(border);
} else {
break;
}
pos.movedir(dir, 2);
}
return llist;
}
},
Board: {
hasborder: 1,
maxFoundNumber: -1,
Expand Down Expand Up @@ -208,14 +231,17 @@
decodePzpr: function(type) {
this.decodeNumber16();
this.decodeEmpty();
this.puzzle.setConfig("loop_full", this.checkpflag("f"));
},
encodePzpr: function(type) {
this.outpflag = this.puzzle.getConfig("loop_full") ? "f" : null;
this.encodeNumber16();
this.encodeEmpty();
}
},
FileIO: {
decodeData: function() {
this.decodeConfigFlag("f", "loop_full");
this.decodeCell(function(cell, ca) {
if (ca === "#") {
cell.ques = 7;
Expand All @@ -228,6 +254,7 @@
this.decodeBorderArrowAns();
},
encodeData: function() {
this.encodeConfigFlag("f", "loop_full");
this.encodeCell(function(cell) {
if (cell.ques === 7) {
return "# ";
Expand All @@ -245,17 +272,21 @@

AnsCheck: {
checklist: [
"checkNumberRange",
"checkNumberRange@trainstations",
"checkBranchLine",
"checkCrossOutOfMark",
"checkCurveOnNumber",
"checkNumberConsecutive",
"checkCurveOnNumber@trainstations",
"checkStraightOnNumber@turnrun",
"checkNumberConsecutive@trainstations",

"checkNotCrossOnMark",
"checkNoLineNumber@turnrun",
"checkDeadendLine+",
"checkOneLoop",
"checkNumberFullSequence",
"checkNoLine"
"checkNumberFullSequence@trainstations",
"checkTurnLengths@turnrun",
"checkNoLine@trainstations",
"checkNoLineIfVariant@turnrun"
],

checkNumberRange: function() {
Expand All @@ -280,6 +311,21 @@
return cell.isLineCurve() && cell.qnum !== -1 && cell.qnum !== 0;
}, "lnCurveOnNum");
},
checkStraightOnNumber: function() {
this.checkAllCell(function(cell) {
return cell.isLineStraight() && cell.qnum !== -1 && cell.qnum !== 0;
}, "lnStraightOnNum");
},

checkTurnLengths: function() {
this.checkWalkGeneric(this.turnrun_walkLine, "ceDirection");
},

checkNoLineNumber: function() {
this.checkAllCell(function(cell) {
return cell.isNum() && cell.lcnt === 0;
}, "numNoLine");
},

checkNumberConsecutive: function() {
var max = this.board.getMaxFoundNumber();
Expand All @@ -302,6 +348,10 @@
},

checkNumberFullSequence: function() {
this.checkWalkGeneric(this.trainstations_walkLine, "nmNotConseqFull");
},

checkWalkGeneric: function(func, code) {
var bd = this.board,
paths = bd.linegraph.components,
path = paths[0];
Expand All @@ -327,7 +377,7 @@
var walks = [];
for (var dir = 1; dir <= 4; dir++) {
if (start.reldirbd(dir, 1).isLine()) {
walks.push(this.walkLine(start, dir));
walks.push(func.call(this, start, dir));
}
}

Expand All @@ -339,7 +389,7 @@
return;
}

this.failcode.add("nmNotConseqFull");
this.failcode.add(code);
if (this.checkOnly) {
return;
}
Expand All @@ -353,7 +403,7 @@
walk.blist.seterr(1);
},

walkLine: function(start, dir) {
trainstations_walkLine: function(start, dir) {
var clist = new this.klass.CellList();
var blist = new this.klass.BorderList();
var current = new this.klass.BorderList();
Expand Down Expand Up @@ -401,6 +451,49 @@
!addr.getc().isEmpty()
);

return { clist: clist, blist: blist };
},

turnrun_walkLine: function(start, dir) {
var clist = new this.klass.CellList();
var blist = new this.klass.BorderList();
var addr = start.getaddr();

do {
var cell = addr.getc();

var segments =
cell.isLineCurve() && cell.isValidNum()
? cell.getSegmentDir(dir)
: null;

if (segments && segments.length !== cell.qnum) {
clist.add(cell);
blist.extend(segments);
}

addr.movedir(dir, 2);

var next = addr.getc();
var adb = next.adjborder;

if (next.lcnt === 4) {
/* Go straight at a crossing */
} else if (dir !== 1 && adb.bottom.isLine()) {
dir = 2;
} else if (dir !== 2 && adb.top.isLine()) {
dir = 1;
} else if (dir !== 3 && adb.right.isLine()) {
dir = 4;
} else if (dir !== 4 && adb.left.isLine()) {
dir = 3;
}
} while (
!addr.equals(start) &&
addr.getc().lcnt > 1 &&
!addr.getc().isEmpty()
);

return { clist: clist, blist: blist };
}
}
Expand Down
54 changes: 54 additions & 0 deletions test/script/turnrun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* turnrun.js */

ui.debug.addDebugData("turnrun", {
url: "5/5/g2o0h1k4j",
failcheck: [
[
"lnBranch",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 0 0 0 /0 0 0 0 /0 0 0 0 /1 0 0 0 /0 0 0 0 /0 0 0 0 0 /0 0 0 0 0 /1 0 0 0 0 /1 0 0 0 0 /"
],
[
"lnCrossExMk",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1 1 0 /0 0 1 1 /0 0 0 0 /0 0 0 0 /0 0 0 0 /0 0 0 1 0 /0 0 0 1 0 /0 0 0 0 0 /0 0 0 0 0 /"
],
[
"lnStraightOnNum",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /1 1 0 0 /1 0 0 1 /1 1 0 0 /0 1 1 0 /1 1 1 1 /1 0 1 0 0 /0 1 1 1 1 /1 1 0 1 1 /1 0 0 0 1 /"
],
[
"ceDirection",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1r 1r 1r /0 0 1 1 /1 1 0 1 /0 1 1 0 /1 1 1 1 /0 1 0 0 1 /0 1 1 0 0 /1 1 0 1 1 /1 0 0 0 1 /"
],
[
"lnNotCrossMk",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1 1 0 /1 0 0 0 /0 0 0 1 /0 0 0 1 /1 1 1 0 /0 1 0 1 0 /1 0 0 1 0 /1 0 0 0 1 /1 0 0 1 0 /"
],
[
"lnPlLoop",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1 1 0 /0 0 1 0 /1 1 0 1 /0 0 0 1 /1 0 0 0 /0 1 0 1 0 /0 1 1 0 0 /1 1 0 1 1 /1 1 0 0 0 /:"
],
[
"numNoLine",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1 1 0 /0 0 1 0 /1 1 0 0 /0 1 1 1 /1 1 1 1 /0 1 0 1 0 /0 1 1 0 0 /1 1 0 0 0 /1 0 0 0 1 /"
],
[
"lnDeadEnd",
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1 1 0 /0 0 0 0 /1 1 0 1 /0 1 1 0 /1 1 1 1 /0 1 0 1 0 /0 1 0 0 0 /1 1 0 1 1 /1 0 0 0 1 /"
],
[
"ceNoLine",
"pzprv3/turnrun/3/3/f/. . 2 /. . . /. . . /1 1 /1 0 /0 1 /1 0 1 /0 1 1 /",
{ skiprules: true }
],
[
null,
"pzprv3/turnrun/3/3/f/. . 2 /. . . /# . . /1 1 /1 0 /0 1 /1 0 1 /0 1 1 /",
{ skiprules: true }
],
[
null,
"pzprv3/turnrun/5/5/. 2 . . . /. . . . . /. 0 . . 1 /. . . . . /4 . . . . /0 1r 1r 0 /0 0 1 0 /1 1 0 1l /0 1 1 0 /1r 1r 1r 1r /0 1 0 1 0 /0 1 1 0 0 /1 1 0 1 1 /1 0 0 0 1 /"
]
],
inputs: []
});

0 comments on commit bdccf7f

Please sign in to comment.