From dcb695a1bff20d4aac58f55378f3393f38143493 Mon Sep 17 00:00:00 2001 From: Lennard Sprong Date: Wed, 4 Dec 2024 20:12:39 +0100 Subject: [PATCH] firewalk: Allow disconnecting corners on fire --- src/variety/icewalk.js | 58 ++++++++++++++++++++++++++++++++--------- test/script/firewalk.js | 15 +++++++++++ 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/variety/icewalk.js b/src/variety/icewalk.js index 1bdd2261f..9960b1ff2 100644 --- a/src/variety/icewalk.js +++ b/src/variety/icewalk.js @@ -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() { @@ -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); @@ -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); } } @@ -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]; } } } @@ -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; @@ -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]) { @@ -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; } @@ -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 === "-") { @@ -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) { @@ -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() { diff --git a/test/script/firewalk.js b/test/script/firewalk.js index be7238b62..ef50e2bfa 100644 --- a/test/script/firewalk.js +++ b/test/script/firewalk.js @@ -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 /" @@ -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 /" } ] });