Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kuromenbun #508

Merged
merged 16 commits into from
May 27, 2024
2 changes: 1 addition & 1 deletion src-ui/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
<main>
<div style="margin-bottom: 5px;"><b>Latest types</b> (<em><a href="/list.html" target="_parent">all types</a></em>)</div>
<ul>
<li><a href="/p?kuromenbun" target="_parent">Kuromenbun クロメンブン</a></li>
<li><a href="/p?portal" target="_parent">Portal Loop</a></li>
<li><a href="/p?teri" target="_parent">Territory テリトリー</a></li>
<li><a href="/p?lixloop" target="_parent">LIX Loop</a></li>
<li><a href="/p?subomino" target="_parent">Subomino</a></li>
<li><a href="/p?retroships" target="_parent">Retrograde Battleships</a></li>
<li><a href="/p?pmemory" target="_parent">Persistence of Memory</a></li>
<li><a href="/p?mrtile" target="_parent">Mirroring Tile ミラーリングタイル</a></li>
</ul>
</main>
</body>
Binary file added src-ui/img/kuromenbun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src-ui/js/ui/KeyPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ ui.keypopup = {
subomino: [10, 0],
lixloop: [130, 0],
teri: [10, 0],
portal: [10, 0]
portal: [10, 0],
kuromenbun: [10, 0]
},

//---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src-ui/js/ui/Misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function toBGimage(pid) {
"kissing",
"kropki",
"kuroclone",
"kuromenbun",
"lollipops",
"magnets",
"mannequin",
Expand Down
1 change: 1 addition & 0 deletions src-ui/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ <h2 id="title"><span lang="ja">パズルの種類のリスト</span><span lang="
<li data-pid="martini"></li>
<li data-pid="patchwork"></li>
<li data-pid="mannequin"></li>
<li data-pid="kuromenbun"></li>
</ul>
</div>
<div class="lists blocks">
Expand Down
1 change: 1 addition & 0 deletions src/pzpr/variety.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
kurochute: [0, 1, "クロシュート", "Kurochute"],
kuroclone: [0, 0, "クロクローン", "Kuroclone"],
kurodoko: [0, 1, "黒どこ(黒マスはどこだ)", "Kurodoko"],
kuromenbun: [0, 0, "クロメンブン", "Kuromenbun"],
kurotto: [0, 0, "クロット", "Kurotto"],
kusabi: [0, 0, "クサビリンク", "Kusabi"],
ladders: [0, 0, "はしごをかけろ", "Ladders"],
Expand Down
2 changes: 2 additions & 0 deletions src/res/failcode.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,10 @@
"nmShadeDiagNe.context": "The number of shaded cells diagonally adjacent to a shaded number is not correct.",
"nmShadeGt.interbd": "The number of shaded cells around a number is not correct.",
"nmShadeGt.kaidan": "The number of circles around a number is not correct.",
"nmShadeGt.kuromenbun": "The number of shaded cells around an area is not correct.",
"nmShadeLt.interbd": "The number of shaded cells around a number is not correct.",
"nmShadeLt.kaidan": "The number of circles around a number is not correct.",
"nmShadeLt.kuromenbun": "The number of shaded cells around an area is not correct.",
"nmShadeNe.lapaz": "The number of shaded cells in the row or column is not correct.",
"nmShadeNe.paintarea": "The number is not equal to the number of shaded cells in the four adjacent cells.",
"nmShadeNe.tawa": "The number of shaded cells around a number is not correct.",
Expand Down
239 changes: 239 additions & 0 deletions src/variety/kuromenbun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/* global Set:false */
(function(pidlist, classbase) {
if (typeof module === "object" && module.exports) {
module.exports = [pidlist, classbase];
} else {
pzpr.classmgr.makeCustom(pidlist, classbase);
}
})(["kuromenbun"], {
MouseEvent: {
use: true,
inputModes: {
edit: ["border", "number", "clear", "info-ublk"],
play: ["shade", "unshade", "info-ublk"]
},
autoedit_func: "areanum",
autoplay_func: "cell",

dispInfoUblk: function() {
var cell = this.getcell();
this.mousereset();
if (cell.isnull || !cell.room) {
return;
}
cell.room.clist.setinfo(1);
cell.room.adjclist.setinfo(2);
this.board.hasinfo = true;
this.puzzle.redraw();
}
},

KeyEvent: {
enablemake: true
},

Cell: {
numberRemainsUnshaded: true,
minnum: 0,
maxnum: function() {
return Math.round((this.board.cols * this.board.rows) / 1.5);
}
},
CellList: {
seterr: function(num) {
if (!this.board.isenableSetError()) {
return;
}
for (var i = 0; i < this.length; i++) {
var old = this[i].error;
this[i].error = old <= 0 ? num : Math.max(old, num);
}
},
setinfo: function(num) {
for (var i = 0; i < this.length; i++) {
var old = this[i].qinfo;
this[i].qinfo = old <= 0 ? num : Math.max(old, num);
}
}
},
Board: {
hasborder: 1,
rows: 8,
cols: 8
},

AreaRoomGraph: {
relation: { "border.ques": "separator", "cell.qans": "node" },
enabled: true,
isnodevalid: function(cell) {
return cell.isUnshade();
},
setExtraData: function(component) {
component.clist = new this.klass.CellList(component.getnodeobjs());

var set = new Set();

component.clist.each(function(cell) {
for (var dir in cell.adjacent) {
var adj = cell.adjacent[dir];
if (!adj.isnull && adj.room !== component) {
set.add(adj);
}
}
});
component.adjclist = new this.klass.CellList(Array.from(set));
}
},

Graphic: {
gridcolor_type: "DARK",

enablebcolor: true,
errbcolor2: "rgb(255, 216, 216)",
errcolor2: "rgb(192, 0, 0)",

getBGCellColor: function(cell) {
if ((cell.error || cell.qinfo) === 1) {
return cell.qsub === 1 ? this.errbcolor2 : this.errbcolor1;
}
return cell.qsub === 1 ? this.bcolor : null;
},

drawDotCells: function() {
var g = this.vinc("cell_dot", "auto", true);

var dsize = Math.max(this.cw * 0.12, 3);
var clist = this.range.cells;
for (var i = 0; i < clist.length; i++) {
var cell = clist[i];

g.vid = "c_dot_" + cell.id;
if (
!cell.isNum() &&
!cell.isShade() &&
(cell.error || cell.qinfo) === 2
) {
g.fillStyle = this.errcolor2;
g.fillCircle(cell.bx * this.bw, cell.by * this.bh, dsize);
} else {
g.vhide();
}
}
},

drawShadedBorders: function() {
this.vinc("wbd", "crispEdges", true);
var g = this.context;
g.lineWidth = this.gw;
g.strokeStyle = this.bbcolor;

var blist = this.range.borders;
for (var i = 0; i < blist.length; i++) {
var border = blist[i];

g.vid = "b_wbd_" + border.id;
if (
!border.isBorder() &&
border.sidecell[0].isShade() &&
border.sidecell[1].isShade()
) {
if (border.isVert()) {
var px = border.bx * this.bw,
py = border.by * this.bh;
g.strokeLine(px, py - this.bh, px, py + this.bh);
} else {
var px = border.bx * this.bw,
py = border.by * this.bh;
g.strokeLine(px - this.bw, py, px + this.bw, py);
}
} else {
g.vhide();
}
}
},

paint: function() {
this.drawBGCells();
this.drawShadedCells();
this.drawGrid();

this.drawDotCells();
this.drawQuesNumbers();

this.drawShadedBorders();
this.drawBorders();

this.drawChassis();

this.drawBoxBorders(false);

this.drawTarget();
}
},

Encode: {
decodePzpr: function(type) {
this.decodeBorder();
this.decodeNumber16();
},
encodePzpr: function(type) {
this.encodeBorder();
this.encodeNumber16();
}
},
FileIO: {
decodeData: function() {
this.decodeBorderQues();
this.decodeCellQnum();
this.decodeCellAns();
},
encodeData: function() {
this.encodeBorderQues();
this.encodeCellQnum();
this.encodeCellAns();
}
},

AnsCheck: {
checklist: [
"checkDoubleNumber",
"checkNumberTooHigh",
"checkNumberTooLow",
"doneShadingDecided"
],
checkNumberTooLow: function() {
this.checkShadeCount(-1, "nmShadeLt");
},
checkNumberTooHigh: function() {
this.checkShadeCount(+1, "nmShadeGt");
},

checkShadeCount: function(factor, code) {
var checkSingleError = !this.puzzle.getConfig("multierr");
var rooms = this.board.roommgr.components;
for (var r = 0; r < rooms.length; r++) {
var room = rooms[r],
num = room.clist.getQnumCell().getNum();
if (num < 0) {
continue;
}

var actual = room.adjclist.filter(function(cell) {
return cell.isShade();
}).length;

if ((factor < 0 && actual < num) || (factor > 0 && actual > num)) {
this.failcode.add(code);
if (this.checkOnly) {
return;
}
room.clist.seterr(1);
room.adjclist.seterr(2);
if (checkSingleError) {
return;
}
}
}
}
}
});
58 changes: 58 additions & 0 deletions test/script/kuromenbun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* kuromenbun.js */

ui.debug.addDebugData("kuromenbun", {
url: "4/4/0q0v282h2j0l5",
failcheck: [
[
"bkNumGe2",
"pzprv3/kuromenbun/4/4/0 0 0 /0 0 1 /1 0 1 /0 0 0 /1 1 1 1 /1 0 0 0 /1 0 0 1 /2 . . 2 /. . . . /0 . . . /. . . 5 /. . . . /. # # . /. . . # /. # . . /"
],
[
"nmShadeGt",
"pzprv3/kuromenbun/4/4/0 0 0 /0 0 1 /1 0 1 /0 0 0 /1 1 1 1 /1 0 0 0 /1 0 0 1 /2 . . 2 /. . . . /0 . . . /. . . 5 /. # # . /# . . # /. . . . /. # . . /"
],
[
"nmShadeLt",
"pzprv3/kuromenbun/4/4/0 0 0 /0 0 1 /1 0 1 /0 0 0 /1 1 1 1 /1 0 0 0 /1 0 0 1 /2 . . 2 /. . . . /0 . . . /. . . 5 /. . # . /. # . # /. . . . /. . . . /"
],
[
null,
"pzprv3/kuromenbun/4/4/0 0 0 /0 0 1 /1 0 1 /0 0 0 /1 1 1 1 /1 0 0 0 /1 0 0 1 /2 . . 2 /. . . . /0 . . . /. . . 5 /+ + # + /+ # + # /+ + + # /+ # + + /"
]
],
inputs: [
{
input: [
"newboard,4,2",
"editmode",
"cursor,1,1",
"mouse,right,1,1",
"mouse,left, 0,2, 6,2, 6,0"
],
result:
"pzprv3/kuromenbun/2/4/0 0 1 /0 0 0 /1 1 1 0 /5 . . . /. . . . /. . . . /. . . . /"
},
{
input: [
"playmode",
"mouse,left,5,3",
"playmode,info-ublk",
"mouse,left,1,3"
],
result: function(puzzle, assert) {
var bd = puzzle.board;
assert.equal(bd.getc(3, 3).qinfo, 1);
assert.equal(bd.getc(5, 3).qinfo, 2);
assert.equal(bd.getc(7, 3).qinfo, 0);
}
},
{
input: ["playmode,info-ublk", "mouse,left,5,3"],
result: function(puzzle, assert) {
var bd = puzzle.board;
assert.equal(bd.getc(5, 3).qinfo, 0);
assert.equal(bd.getc(5, 1).qinfo, 0);
}
}
]
});
Loading