Skip to content

Commit

Permalink
numlin: Highlight paired line when clicking unfinished path
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep committed Feb 6, 2025
1 parent 7d6e5b9 commit 4d17f2d
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 6 deletions.
47 changes: 45 additions & 2 deletions src/variety/numlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,47 @@
play: ["line", "peke", "info-line"]
},
autoedit_func: "qnum",
autoplay_func: "line"
autoplay_func: "line",

dispInfoLine: function() {
var bd = this.board,
cell = this.getcell();
if (cell.isnull) {
return;
}

var number = cell.getNum();
if (number < 0 && cell.path) {
var numcell = cell.path.clist.filter(function(s) {
return s.isValidNum();
})[0];
if (numcell) {
number = numcell.getNum();
} else {
bd.border.setinfo(-1);
cell.path.setedgeinfo(1);
bd.hasinfo = true;
this.puzzle.redraw();
return;
}
}
if (number > 0) {
bd.border.setinfo(-1);

bd.cell.filter(function(c) {
if (c.getNum() !== number) {
return;
}
c.setinfo(1);

if (c.path) {
c.path.setedgeinfo(1);
}
});
bd.hasinfo = true;
this.puzzle.redraw();
}
}
},

//---------------------------------------------------------
Expand Down Expand Up @@ -80,7 +120,10 @@
var cell = clist[i];
g.vid = "c_sq_" + cell.id;
if (cell.qnum !== -1) {
g.fillStyle = cell.error === 1 ? this.errbcolor1 : this.bgcolor;
g.fillStyle =
cell.error === 1 || cell.qinfo === 1
? this.errbcolor1
: this.bgcolor;
g.fillRectCenter(cell.bx * this.bw, cell.by * this.bh, rw, rh);
} else {
g.vhide();
Expand Down
63 changes: 59 additions & 4 deletions test/script/numlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,76 @@ ui.debug.addDebugData("numlin", {
/* 問題入力はnurikabeと同じなので省略 */
/* 回答入力はmashuと同じなので省略 */
/* AreaLineManagerでエラーしないか確認 */
{ input: ["newboard,5,2", "playmode"] },
{
input: [
"newboard,5,2",
"editmode",
"cursor,7,1",
"key,1",
"cursor,3,3",
"key,1",
"cursor,9,3",
"key,2",
"cursor,1,3",
"key,2"
],
result:
"pzprv3/numlin/2/5/. . . 1 . /2 1 . . 2 /0 0 0 0 /0 0 0 0 /0 0 0 0 0 /"
},
{
input: [
"playmode,auto",
"mouse,left, 1,1, 7,1",
"mouse,left, 3,3, 9,3",
"mouse,left, 5,1, 5,3",
"mouse,right, 6,3, 5,2"
],
result:
"pzprv3/numlin/2/5/. . . . . /. . . . . /1 1 1 0 /0 1 -1 1 /0 0 -1 0 0 /"
"pzprv3/numlin/2/5/. . . 1 . /2 1 . . 2 /1 1 1 0 /0 1 -1 1 /0 0 -1 0 0 /"
},
{
label: "Highlight lines",
input: ["playmode,info-line", "mouse,left,3,1"],
result: function(puzzle, assert) {
var bd = puzzle.board;

assert.equal(bd.getc(1, 3).qinfo, 0);
assert.equal(bd.getc(9, 3).qinfo, 0);
assert.equal(bd.getb(8, 3).qinfo, -1);

assert.equal(bd.getc(7, 1).qinfo, 1);
assert.equal(bd.getb(2, 1).qinfo, 1);
assert.equal(bd.getb(4, 3).qinfo, 1);
}
},
{
label: "Highlight lines by clicking number",
input: ["playmode,info-line", "mouse,left,1,3"],
result: function(puzzle, assert) {
var bd = puzzle.board;

assert.equal(bd.getc(1, 3).qinfo, 1);
assert.equal(bd.getc(9, 3).qinfo, 1);
assert.equal(bd.getb(8, 3).qinfo, 1);

assert.equal(bd.getc(7, 1).qinfo, 0);
assert.equal(bd.getb(2, 1).qinfo, -1);
assert.equal(bd.getb(4, 3).qinfo, -1);
}
},
{
input: ["mouse,left, 5,1, 5,3, 7,3"],
input: ["playmode,auto", "mouse,left, 5,1, 5,3, 7,3"],
result:
"pzprv3/numlin/2/5/. . . . . /. . . . . /1 1 1 0 /0 1 1 1 /0 0 1 0 0 /"
"pzprv3/numlin/2/5/. . . 1 . /2 1 . . 2 /1 1 1 0 /0 1 1 1 /0 0 1 0 0 /"
},
{
input: ["mouse,left,7,1,5,1,5,3", "playmode,info-line", "mouse,left,1,1"],
result: function(puzzle, assert) {
var bd = puzzle.board;

assert.equal(bd.getb(4, 1).qinfo, 1);
assert.equal(bd.getb(8, 3).qinfo, -1);
}
}
]
});

0 comments on commit 4d17f2d

Please sign in to comment.