Skip to content

Commit

Permalink
firewalk: Allow disconnecting corners on fire
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep committed Dec 4, 2024
1 parent 0a94116 commit dcb695a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
58 changes: 46 additions & 12 deletions src/variety/icewalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,21 @@
},
toggleArcs: function() {
var cell = this.getcell();
if (cell.isnull || !cell.ice() || cell.lcnt < 3) {
if (
cell.isnull ||
!cell.ice() ||
(cell.lcnt < 3 && !cell.isLineCurve())
) {
return;
}
cell.setQans(cell.qans !== 1 ? 1 : 2);

if (cell.lcnt > 2) {
cell.setQans(cell.qans !== 1 ? 1 : 2);
} else if (cell.qans === 3) {
cell.updateFireQans();
} else {
cell.setQans(3);
}
cell.drawaround();
},
inputLine: function() {
Expand Down Expand Up @@ -131,7 +142,13 @@
Math.max(horz.bx, vert.bx),
Math.max(horz.by, vert.by)
)[0];
if (cell && !cell.isnull && cell.ice() && cell.lcnt >= 3) {

if (
cell &&
!cell.isnull &&
cell.ice() &&
(cell.lcnt >= 3 || cell.qans === 3)
) {
var newQans =
(cell.adjborder.top === horz) ===
(cell.adjborder.left === vert);
Expand Down Expand Up @@ -211,7 +228,12 @@
var newQans =
this.adjborder.top.isLine() === this.adjborder.left.isLine();
this.setQans(newQans ? 1 : 2);
} else if (!this.ice() || this.lcnt < 2 || this.isLineStraight()) {
} else if (
!this.ice() ||
this.lcnt < 2 ||
this.isLineStraight() ||
this.qans === 3
) {
this.setQans(0);
}
}
Expand Down Expand Up @@ -282,7 +304,7 @@
var clist = this.board.cell;
for (var i = 0; i < clist.length; i++) {
var cell = clist[i];
cell.qans = { 0: 0, 1: 2, 2: 1 }[cell.qans];
cell.qans = { 0: 0, 1: 2, 2: 1, 3: 3 }[cell.qans];
}
}
}
Expand Down Expand Up @@ -366,6 +388,13 @@
this.bw - pad,
this.bh - pad
);
} else if (cell.qans === 3) {
g.fillRectCenter(
cell.bx * this.bw,
cell.by * this.bh,
this.bw / 2,
this.bh / 2
);
} else {
var adj = cell.adjborder;
var ox, oy;
Expand Down Expand Up @@ -489,7 +518,7 @@
}
}

var otherdir = [cell.DN, cell.LT, cell.RT][cell.qans];
var otherdir = [cell.DN, cell.LT, cell.RT, cell.DN][cell.qans];

for (var dir = 1; dir <= 4; dir++) {
if (!reusenodes[dir]) {
Expand Down Expand Up @@ -535,7 +564,7 @@
return sidenodes;
},
usesSecondNode: function(cell, other) {
var otherdir = [cell.DN, cell.LT, cell.RT][cell.qans];
var otherdir = [cell.DN, cell.LT, cell.RT, cell.DN][cell.qans];
var dir = cell.getdir(other, 2);
return dir === cell.UP || dir === otherdir;
}
Expand Down Expand Up @@ -573,6 +602,9 @@
} else if (ca === "B") {
cell.ques = 6;
cell.qans = 2;
} else if (ca === "C") {
cell.ques = 6;
cell.qans = 3;
} else if (ca === "#") {
cell.ques = 6;
} else if (ca === "-") {
Expand All @@ -590,10 +622,8 @@
},
encodeData: function() {
this.encodeCell(function(cell) {
if (cell.qans === 1) {
return "A ";
} else if (cell.qans === 2) {
return "B ";
if (cell.qans > 0) {
return String.fromCharCode(64 + cell.qans) + " ";
} else if (cell.ques === 6) {
return "# ";
} else if (cell.qnum === -2) {
Expand Down Expand Up @@ -710,7 +740,11 @@
},
checkDeadendLine: function() {
this.checkAllCell(function(cell) {
return cell.lcnt === 1 || (cell.lcnt === 3 && cell.qans > 0);
return (
cell.lcnt === 1 ||
cell.qans === 3 ||
(cell.lcnt === 3 && cell.qans > 0)
);
}, "lnDeadEnd");
},
checkStraightOnFire: function() {
Expand Down
15 changes: 15 additions & 0 deletions test/script/firewalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ ui.debug.addDebugData("firewalk", {
"lnDeadEnd",
"pzprv3/firewalk/5/5/. 11 . 3 . /. . A A . /. . A B . /. . . 2 . /11 . 11 . # /0 1 0 0 1 0 /0 0 0 1 1 0 /0 0 1 1 1 0 /0 0 0 0 0 0 /0 1 1 0 1 0 /0 0 0 0 0 /1 1 0 1 1 /1 1 1 1 0 /1 0 1 1 0 /1 0 1 1 0 /0 0 0 0 0 /"
],
[
"lnDeadEnd",
"pzprv3/firewalk/2/2/C . /. . /0 1 0 /0 1 0 /0 0 /1 1 /0 0 /",
{ skiprules: true }
],
[
null,
"pzprv3/firewalk/5/5/. 11 . 3 . /. . A A . /. . A B . /. . . 2 . /11 . 11 . A /0 1 0 0 1 0 /0 0 0 1 1 0 /0 0 1 1 1 0 /0 0 0 0 0 0 /0 1 1 0 1 0 /0 0 0 0 0 /1 1 0 1 1 /1 1 1 1 0 /1 0 1 1 1 /1 0 1 1 1 /0 0 0 0 0 /"
Expand Down Expand Up @@ -83,6 +88,16 @@ ui.debug.addDebugData("firewalk", {
input: ["mouse,right,2,2", "mouse,left,4,2"],
result:
"pzprv3/firewalk/3/3/. . . /. # . /. . . /0 0 1 0 /0 0 0 0 /0 1 0 0 /0 0 0 /0 1 0 /0 1 0 /0 0 0 /0 0 0 0 /0 1 2 0 /0 0 0 0 /0 0 0 0 /"
},
{
input: ["mouse,left,5,1,3,1,3,3", "mouse,left,3,3,5,3", "mouse,left,3,3"],
result:
"pzprv3/firewalk/3/3/. . . /. C . /. . . /0 0 0 0 /0 0 1 0 /0 1 0 0 /0 0 0 /0 0 0 /0 1 0 /0 0 0 /0 0 0 0 /0 1 2 0 /0 0 0 0 /0 0 0 0 /"
},
{
input: ["mouse,left,3,3"],
result:
"pzprv3/firewalk/3/3/. . . /. A . /. . . /0 0 0 0 /0 0 1 0 /0 1 0 0 /0 0 0 /0 0 0 /0 1 0 /0 0 0 /0 0 0 0 /0 1 2 0 /0 0 0 0 /0 0 0 0 /"
}
]
});

0 comments on commit dcb695a

Please sign in to comment.