-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathnurikabe.js
More file actions
398 lines (379 loc) · 8.69 KB
/
Copy pathnurikabe.js
File metadata and controls
398 lines (379 loc) · 8.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
//
// パズル固有スクリプト部 ぬりかべ・ぬりぼう・モチコロ・モチにょろ版 nurikabe.js
//
(function(pidlist, classbase) {
if (typeof module === "object" && module.exports) {
module.exports = [pidlist, classbase];
} else {
pzpr.classmgr.makeCustom(pidlist, classbase);
}
})(["nurikabe", "nuribou", "mochikoro", "mochinyoro"], {
//---------------------------------------------------------
// マウス入力系
MouseEvent: {
use: true,
inputModes: { edit: ["number", "clear"], play: ["shade", "unshade"] },
mouseinput_auto: function() {
if (this.puzzle.playmode) {
if (this.mousestart || this.mousemove) {
this.inputcell();
}
} else if (this.puzzle.editmode) {
if (this.mousestart) {
this.inputqnum();
}
}
}
},
"MouseEvent@nurikabe": {
inputModes: {
edit: ["number", "clear", "info-blk"],
play: ["shade", "unshade", "info-blk"]
}
},
//---------------------------------------------------------
// キーボード入力系
KeyEvent: {
enablemake: true
},
//---------------------------------------------------------
// 盤面管理系
Cell: {
numberRemainsUnshaded: true
},
"Cell@mochikoro,mochinyoro": {
getdir8clist: function() {
var list = [];
var cells = [
this.relcell(-2, -2),
this.relcell(0, -2),
this.relcell(2, -2),
this.relcell(-2, 0),
this.relcell(2, 0),
this.relcell(-2, 2),
this.relcell(0, 2),
this.relcell(2, 2)
];
for (var i = 0; i < 8; i++) {
if (cells[i].group === "cell" && !cells[i].isnull) {
list.push([cells[i], i + 1]);
} /* i+1==dir */
}
return list;
}
},
"Board@mochikoro,mochinyoro": {
addExtraInfo: function() {
this.ublk8mgr = this.addInfoList(this.klass.AreaUnshade8Graph);
}
},
AreaShadeGraph: {
enabled: true
},
"AreaShadeGraph@mochikoro": {
enabled: false
},
AreaUnshadeGraph: {
enabled: true
},
"AreaUnshade8Graph:AreaUnshadeGraph@mochikoro,mochinyoro": {
setComponentRefs: function(obj, component) {
obj.ublk8 = component;
},
getObjNodeList: function(nodeobj) {
return nodeobj.ublk8nodes;
},
resetObjNodeList: function(nodeobj) {
nodeobj.ublk8nodes = [];
},
getSideObjByNodeObj: function(cell) {
var list = cell.getdir8clist(),
cells = [];
for (var i = 0; i < list.length; i++) {
var cell2 = list[i][0];
if (this.isnodevalid(cell2)) {
cells.push(cell2);
}
}
return cells;
}
},
//---------------------------------------------------------
// 画像表示系
Graphic: {
numbercolor_func: "qnum",
qanscolor: "black",
paint: function() {
this.drawBGCells();
this.drawShadedCells();
if (this.pid === "nurikabe") {
this.drawDotCells();
}
this.drawGrid();
this.drawQuesNumbers();
this.drawChassis();
this.drawTarget();
}
},
"Graphic@nuribou,mochikoro,mochinyoro": {
bgcellcolor_func: "qsub1",
enablebcolor: true
},
//---------------------------------------------------------
// URLエンコード/デコード処理
Encode: {
decodePzpr: function(type) {
this.decodeNumber16();
},
encodePzpr: function(type) {
this.encodeNumber16();
}
},
"Encode@nurikabe": {
decodeKanpen: function() {
this.fio.decodeCellQnum_kanpen();
},
encodeKanpen: function() {
this.fio.encodeCellQnum_kanpen();
}
},
//---------------------------------------------------------
FileIO: {
decodeData: function() {
this.decodeCellQnum();
this.decodeCellAns();
},
encodeData: function() {
this.encodeCellQnum();
this.encodeCellAns();
}
},
"FileIO@nurikabe": {
decodeData: function() {
this.decodeCellQnumAns();
},
encodeData: function() {
this.encodeCellQnumAns();
},
kanpenOpen: function() {
this.decodeCellQnumAns_kanpen();
},
kanpenSave: function() {
this.encodeCellQnumAns_kanpen();
},
kanpenOpenXML: function() {
this.decodeCellQnumAns_XMLBoard();
},
kanpenSaveXML: function() {
this.encodeCellQnumAns_XMLBoard();
this.encodeCellAns_XMLAnswer();
},
decodeCellQnumAns_XMLBoard: function() {
this.decodeCellXMLBoard(function(cell, val) {
if (val > 0) {
cell.qnum = val;
} else if (val === -1) {
cell.qsub = 1;
} else if (val === -2) {
cell.qans = 1;
} else if (val === -3) {
cell.qnum = -2;
}
});
},
encodeCellQnumAns_XMLBoard: function() {
this.encodeCellXMLBoard(function(cell) {
var val = 0;
if (cell.qnum > 0) {
val = cell.qnum;
} else if (cell.qnum === -2) {
val = -3;
} else if (cell.qans === 1) {
val = -2;
} else if (cell.qsub === 1) {
val = -1;
}
return val;
});
}
},
//---------------------------------------------------------
// 正解判定処理実行部
"AnsCheck@nurikabe": {
checklist: [
"check2x2ShadeCell",
"checkNoNumberInUnshade",
"checkConnectShade",
"checkDoubleNumberInUnshade",
"checkNumberAndUnshadeSize",
"doneShadingDecided"
]
},
"AnsCheck@nuribou#1": {
checklist: [
"checkBou",
"checkCorners",
"checkNoNumberInUnshade",
"checkDoubleNumberInUnshade",
"checkNumberAndUnshadeSize",
"doneShadingDecided"
]
},
"AnsCheck@mochikoro,mochinyoro#1": {
checklist: [
"checkShadeCellExist",
"check2x2ShadeCell",
"checkConnectUnshaded_mochikoro",
"checkUnshadeRect",
"checkDoubleNumberInUnshade",
"checkNumberAndUnshadeSize",
"checkShadeNotRect@mochinyoro",
"doneShadingDecided"
]
},
AnsCheck: {
checkDoubleNumberInUnshade: function() {
this.checkAllBlock(
this.board.ublkmgr,
function(cell) {
return cell.isNum();
},
function(w, h, a, n) {
return a < 2;
},
"bkNumGe2"
);
},
checkNumberAndUnshadeSize: function() {
this.checkAllArea(
this.board.ublkmgr,
function(w, h, a, n) {
return n <= 0 || n === a;
},
"bkSizeNe"
);
}
},
"AnsCheck@nuribou": {
checkBou: function() {
this.checkAllArea(
this.board.sblkmgr,
function(w, h, a, n) {
return w === 1 || h === 1;
},
"csWidthGt1"
);
},
checkCorners: function() {
var bd = this.board;
for (var c = 0; c < bd.cell.length; c++) {
var cell = bd.cell[c];
if (cell.bx === bd.maxbx - 1 || cell.by === bd.maxby - 1) {
continue;
}
var i,
adc = cell.adjacent;
var cells = [
[cell, adc.right.adjacent.bottom],
[adc.right, adc.bottom]
];
for (i = 0; i < 2; i++) {
if (cells[i][0].isShade() && cells[i][1].isShade()) {
break;
}
}
if (i === 2) {
continue;
}
var block1 = cells[i][0].sblk.clist,
block2 = cells[i][1].sblk.clist;
if (block1.length !== block2.length) {
continue;
}
this.failcode.add("csCornerSize");
if (this.checkOnly) {
break;
}
block1.seterr(1);
block2.seterr(1);
}
}
},
"AnsCheck@nurikabe,nuribou": {
checkNoNumberInUnshade: function() {
this.checkAllBlock(
this.board.ublkmgr,
function(cell) {
return cell.isNum();
},
function(w, h, a, n) {
return a !== 0;
},
"bkNoNum"
);
}
},
"AnsCheck@mochikoro,mochinyoro": {
checkConnectUnshaded_mochikoro: function() {
this.checkOneArea(this.board.ublk8mgr, "csDivide8");
},
checkUnshadeRect: function() {
this.checkAllArea(
this.board.ublkmgr,
function(w, h, a, n) {
return w * h === a;
},
"cuNotRect"
);
}
},
"AnsCheck@mochinyoro": {
checkShadeNotRect: function() {
this.checkAllArea(
this.board.sblkmgr,
function(w, h, a, n) {
return w * h !== a;
},
"csRect"
);
}
},
FailCode: {
bkNoNum: [
"数字の入っていないシマがあります。",
"An area of unshaded cells has no numbers."
],
bkNumGe2: [
"1つのシマに2つ以上の数字が入っています。",
"An area of unshaded cells has more than one number."
],
bkSizeNe: [
"数字とシマの面積が違います。",
"The number is not equal to the size of the area."
]
},
"FailCode@nuribou": {
csWidthGt1: [
"「幅1マス、長さ1マス以上」ではない黒マスのカタマリがあります。",
"There is a mass of shaded cells whose width is more than two."
],
csCornerSize: [
"同じ面積の黒マスのカタマリが、角を共有しています。",
"Masses of shaded cells with the same length share a corner."
]
},
"FailCode@mochikoro,mochinyoro": {
cuNotRect: [
"四角形でない白マスのブロックがあります。",
"There is a block of unshaded cells that is not a rectangle."
],
csRect: [
"四角形になっている黒マスのブロックがあります。",
"There is a block of shaded cells that is a rectangle."
],
csDivide8: [
"孤立した白マスのブロックがあります。",
"The unshaded cells are divided."
]
}
});