-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathcurvedata.js
More file actions
1388 lines (1198 loc) · 30.2 KB
/
Copy pathcurvedata.js
File metadata and controls
1388 lines (1198 loc) · 30.2 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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// curvedata.js: Implementation of Curve Data puzzle type.
//
/* global Set:false */
(function(pidlist, classbase) {
if (typeof module === "object" && module.exports) {
module.exports = [pidlist, classbase];
} else {
pzpr.classmgr.makeCustom(pidlist, classbase);
}
})(["curvedata", "curvedata-aux"], {
// In this puzzle, clue numbers are not stable. They can be changed on the entire board
// by a call to `compressShapes()`. Operations which change qnum directly are not permitted.
// Use CurveDataOperation for all changes to clues on the grid.
"MouseEvent@curvedata": {
inputModes: {
edit: ["copy-answer", "move-clue", "border", "shade", "undef", "clear"],
play: ["line", "peke"]
},
mouseinput_auto: function() {
if (this.puzzle.playmode) {
if (this.btn === "left") {
if (this.mousestart || this.mousemove) {
this.inputLine();
} else if (this.mouseend && this.notInputted()) {
this.inputpeke();
}
} else if (this.btn === "right") {
if (this.mousestart || this.mousemove) {
this.inputpeke();
}
}
} else if (this.puzzle.editmode && this.mousestart) {
var cell = this.getcell();
if (cell.isnull) {
return;
}
this.setcursor(cell);
var shape = this.board.shapes[cell.qnum];
var w = this.puzzle.board.cols;
var h = this.puzzle.board.rows;
if (shape && shape.w > 0) {
w = Math.max(w, shape.w);
h = Math.max(h, shape.bits.length / shape.w);
}
var s = Math.max(w, h);
var data = [s, s];
if (shape && shape.w > 0) {
data.push(shape.w);
data.push(shape.bits.length / shape.w);
data.push(shape.encodeBits());
}
var thiz = this;
var args = {
pid: "curvedata-aux",
key: cell.bx + "," + cell.by,
url: data.join("/")
};
this.puzzle.emit("request-aux-editor", args, function(auxpuzzle) {
var shape = auxpuzzle.board.getShape();
if (shape || cell.qnum >= 0) {
thiz.addOperation(cell, shape);
}
});
}
},
addOperation: function(cell, shape) {
var ope = new this.klass.CurveDataOperation(cell, shape);
if (ope.isvalid) {
ope.redo();
this.puzzle.opemgr.add(ope);
cell.draw();
}
},
inputShade: function() {
return this.enterqnum(-3);
},
mouseinput_undef: function() {
return this.enterqnum(-2);
},
mouseinput_clear: function() {
return this.enterqnum(-1);
},
enterqnum: function(value) {
var cell = this.getcell();
if (cell.isnull || cell === this.mouseCell || !this.puzzle.editmode) {
return;
}
this.mouseCell = cell;
if (this.mousestart) {
this.inputData = cell.qnum !== value ? value : -1;
}
if (this.inputData === -3) {
["left", "right", "top", "bottom"].forEach(function(dir) {
if (!cell.adjborder[dir].isnull) {
cell.adjborder[dir].setQues(0);
cell.adjborder[dir].removeLine();
}
});
}
this.addOperation(cell, this.inputData);
},
mouseinput_other: function() {
if (this.inputMode === "copy-answer" && this.mousestart) {
this.mouseinput_copyAnswer();
}
if (this.inputMode === "move-clue") {
this.mouseinput_moveClue();
}
},
mouseinput_copyAnswer: function() {
var cell = this.getcell();
if (cell.isnull || !this.puzzle.editmode) {
return;
}
if (!cell.path) {
return;
}
var shape = cell.path.clist.toCurveData();
this.addOperation(cell, shape);
},
mouseinput_moveClue: function() {
var cell = this.getcell();
if (this.mousestart) {
this.mouseCell = cell.qnum !== -1 && cell.qnum !== -3 ? cell : null;
return;
}
if (!this.mouseCell || cell.isnull) {
return;
}
if (!this.mouseCell.equals(cell) && cell.qnum === -1) {
var swap =
this.board.shapes[this.mouseCell.qnum] || this.mouseCell.qnum;
this.addOperation(cell, swap);
this.addOperation(this.mouseCell, -1);
this.mouseCell = cell;
}
}
},
"MouseEvent@curvedata-aux": {
inputModes: { edit: [], play: ["line", "slide"] },
mouseinput_auto: function() {
this.inputLine();
},
mouseinput_other: function() {
if (this.inputMode === "slide") {
this.mouseinput_slide();
}
},
mouseinput_slide: function() {
var cell = this.getcell();
if (this.mousestart) {
this.inputData = cell.lcnt > 0 ? cell : null;
return;
}
if (!this.inputData || cell.isnull) {
return;
}
if (
this.inputData.bx < cell.bx &&
this.addSlideOperation("R", this.inputData)
) {
this.inputData = this.inputData.adjacent.right;
} else if (
this.inputData.bx > cell.bx &&
this.addSlideOperation("L", this.inputData)
) {
this.inputData = this.inputData.adjacent.left;
} else if (
this.inputData.by < cell.by &&
this.addSlideOperation("D", this.inputData)
) {
this.inputData = this.inputData.adjacent.bottom;
} else if (
this.inputData.by > cell.by &&
this.addSlideOperation("U", this.inputData)
) {
this.inputData = this.inputData.adjacent.top;
}
},
addSlideOperation: function(dir, cell) {
var ope = new this.klass.SlideOperation(dir, cell);
if (ope.isvalid()) {
ope.redo();
this.puzzle.opemgr.add(ope);
return true;
}
return false;
}
},
Border: {
enableLineNG: true,
isLineNG: function() {
return (
this.ques === 1 ||
this.sidecell[0].qnum === -3 ||
this.sidecell[1].qnum === -3
);
},
prehook: {
ques: function(num) {
if (num > 0) {
this.removeLine();
}
return false;
}
}
},
Board: {
hasborder: 1,
shapes: [],
createExtraObject: function() {
this.shapes = [];
},
compressShapes: function() {
var map = {};
var i;
for (i = 0; i < this.cell.length; i++) {
map[this.cell[i].qnum] = true;
}
map[-1] = -1;
map[-2] = -2;
map[-3] = -3;
var next = 0;
for (i = 0; i < this.shapes.length; i++) {
if (i in map) {
map[i] = next++;
}
}
if (next !== i) {
for (i = 0; i < this.cell.length; i++) {
this.cell[i].qnum = map[this.cell[i].qnum];
}
for (i = 0; i < this.shapes.length; i++) {
this.shapes[map[i]] = this.shapes[i];
}
this.shapes = this.shapes.slice(0, next);
for (i = 0; i < this.linegraph.components.length; i++) {
var path = this.linegraph.components[i];
path.isomorphicWith = null;
this.linegraph.components.scanForClues(path);
}
}
}
},
"Board@curvedata-aux": {
setShape: function(shape) {
var w = shape.w;
var h = shape.bits.length / w;
var sx = (this.cols - w) | 1;
var sy = (this.rows - h) | 1;
for (var y = 0; y < h; y++) {
for (var x = 0; x < w; x++) {
var cell = this.getc(x * 2 + sx, y * 2 + sy);
if (!cell || cell.isnull) {
continue;
}
if (shape.bits[y * w + x] & 1 && !cell.adjborder.right.isnull) {
cell.adjborder.right.setLine(1);
}
if (shape.bits[y * w + x] & 2 && !cell.adjborder.bottom.isnull) {
cell.adjborder.bottom.setLine(1);
}
}
}
},
getShape: function() {
var path = this.cell.filter(function(cell) {
return cell.lcnt > 0;
});
return (
path && path.length > 0 && new this.klass.CellList(path).toCurveData()
);
}
},
CurveData: {
// A curve data clue is defined by an array of numbers 0-15, and a width.
// Each number is made of four bits. Only the lower two bits can be modified,
// the other bits are set by a call to `buildBits()`.
// 1 = horizontal line connecting right
// 2 = vertical line connecting down
// 4 = horizontal line connecting left
// 8 = vertical line connecting up
//
// The values 5 and 10 are special, as they represent a straight line of length 1.
// These are not part of the graph, since lines can be of any length.
bits: [],
w: 0,
// The following field is derived from the `bits` and `w` values.
// If its value is null, `build()` must be called to fill it.
//
// Connections is an array representing the graph, with one element for each
// meaningful node in `bits` (not 0, 5, or 10). Each element is an array of
// length 4 representing graph indices of nodes connected right, down, left,
// and up, in this order. Null represents no node in that direction.
connections: null,
// Cached result of encodeBits().
serialized: null,
initialize: function() {
this.w = 0;
this.bits = [];
this.invalidate();
},
init: function(rows, cols) {
var len = rows * cols;
this.w = rows;
this.bits = Array(len);
for (var i = 0; i < len; i++) {
this.bits[i] = 0;
}
this.invalidate();
},
invalidate: function() {
this.connections = null;
this.serialized = null;
},
buildBits: function() {
var len = this.bits.length;
var w = this.w;
// Complete the bits array.
for (var id = 0; id < len; id++) {
this.bits[id] &= 3;
var x = Math.floor(id % w);
var y = Math.floor(id / w);
if (x > 0 && this.bits[y * w + x - 1] & 1) {
this.bits[id] |= 4;
}
if (y > 0 && this.bits[(y - 1) * w + x] & 2) {
this.bits[id] |= 8;
}
}
},
build: function() {
this.connections = [];
this.buildBits();
var left = null;
var above = new Array(this.w);
for (var id = 0; id < this.bits.length; id++) {
var key = this.bits[id];
if (key === 0 || key === 5 || key === 10) {
continue;
}
var x = id % this.w;
var node = this.connections.length;
var conns = [null, null, null, null];
if (key & 4) {
conns[2] = left;
this.connections[left][0] = node;
}
if (key & 8) {
conns[3] = above[x];
this.connections[above[x]][1] = node;
}
left = node;
above[x] = node;
this.connections.push(conns);
}
},
// Constructs a string with the following traits:
// - depends only on `connections` and the argument `root`
// - ignores the order of elements in `connections` other than `connections[root]`
// - unambiguously describes a curve isomorphic with `connections`
// In consequence, if two curves are isomorphic, the sets of strings
// they can produce for all possible values of `root` are identical.
// If two curves are NOT isomorphic, then those sets have no overlap.
constructDfsString: function(root) {
var result = "";
var stack = [{ node: root, parent: null, str: "" }];
var index = 0;
var order = new Array(this.connections.length);
for (var i = 0; i < order.length; i++) {
order[i] = null;
}
while (stack.length > 0) {
var current = stack.pop();
result += current.str;
var node = current.node;
// Using null as "return to parent" marker to append "^" to the string.
if (node === null) {
continue;
}
stack.push({ node: null, parent: node, str: "^" });
// When encountering a previously visited node, append its index in
// visiting order to the string. This will always be followed by a
// return to parent so there is no danger of concatenating two numbers.
if (order[node] !== null) {
result += order[node];
continue;
}
order[node] = index;
index++;
for (var dir = 0; dir < 4; dir++) {
var child = this.connections[node][dir];
if (child !== null && child !== current.parent) {
var prefix = ["R", "D", "L", "U"][dir];
stack.push({ node: child, parent: node, str: prefix });
}
}
}
return result;
},
deepEquals: function(other) {
return (
other && this.w === other.w && this.encodeBits() === other.encodeBits()
);
},
isIsomorphic: function(other) {
if (!other) {
return false;
}
if (!this.connections) {
this.build();
}
if (!other.connections) {
other.build();
}
if (this.connections.length !== other.connections.length) {
return false;
}
if (this.connections.length === 0 && other.connections.length === 0) {
return true;
}
var key = other.constructDfsString(0);
for (var i = 0; i < this.connections.length; i++) {
if (this.constructDfsString(i) === key) {
return true;
}
}
return false;
},
encodeBits: function() {
if (this.serialized !== null) {
return this.serialized;
}
var bits = "";
var len = this.bits.length;
for (var b = 0; b < len - 1; b += 2) {
var bit = this.bits[b] & 3;
bit |= (this.bits[b + 1] & 3) << 2;
bits += bit.toString(16);
}
this.serialized = bits;
return bits;
},
decodeBits: function(code) {
var len = this.bits.length;
for (var b = 0; b < len - 1; b += 2) {
var num = parseInt(code[b / 2], 16);
this.bits[b] = num & 3;
this.bits[b + 1] = (num & 12) >> 2;
}
this.invalidate();
}
},
"CurveDataOperation:Operation": {
type: "curvedata",
setData: function(cell, shape) {
var old = cell.board.shapes[cell.qnum];
if (old) {
this.oldw = old.w;
this.oldh = old.bits.length / old.w;
this.oldbits = old.encodeBits();
} else {
this.oldqnum = cell.qnum;
}
if (shape && typeof shape === "object") {
if (shape.bits.length > 0) {
this.neww = shape.w;
this.newh = shape.bits.length / shape.w;
this.newbits = shape.encodeBits();
} else {
this.newqnum = -1;
}
} else if (typeof shape === "number" && shape < 0) {
this.newqnum = shape;
} else if (!shape && shape !== 0) {
this.newqnum = -1;
} else {
throw Error("Can only set shapes or negative qnum values");
}
this.x = cell.bx;
this.y = cell.by;
this.isvalid =
this.oldw !== this.neww ||
this.oldh !== this.newh ||
this.oldbits !== this.newbits ||
this.oldqnum !== this.newqnum;
},
decode: function(strs) {
var i = 0;
if (strs[i++] !== "DC") {
return false;
}
this.x = +strs[i++];
this.y = +strs[i++];
this.neww = +strs[i++];
this.newh = +strs[i++];
this.newbits = strs[i++];
this.newqnum = +strs[i++];
this.oldw = +strs[i++];
this.oldh = +strs[i++];
this.oldbits = strs[i++];
this.oldqnum = +strs[i++];
return true;
},
toString: function() {
return [
"DC",
this.x,
this.y,
this.neww,
this.newh,
this.newbits,
this.newqnum,
this.oldw,
this.oldh,
this.oldbits,
this.oldqnum
].join(",");
},
undo: function() {
if (this.oldqnum) {
this.execNum(this.oldqnum);
} else {
this.execShape(this.oldw, this.oldh, this.oldbits);
}
},
redo: function() {
if (this.newqnum) {
this.execNum(this.newqnum);
} else {
this.execShape(this.neww, this.newh, this.newbits);
}
},
execShape: function(w, h, data) {
var shape = new this.klass.CurveData();
shape.init(w, h);
shape.decodeBits(data);
var len = this.board.shapes.length;
for (var i = 0; i < len; i++) {
if (this.board.shapes[i].deepEquals(shape)) {
return this.execNum(i);
}
}
this.board.shapes.push(shape);
return this.execNum(len);
},
execNum: function(num) {
var cell = this.board.getc(this.x, this.y);
cell.qnum = num;
if (cell.path) {
this.board.linegraph.scanForClues(cell.path);
}
cell.draw();
}
},
"SlideOperation:Operation": {
setData: function(dir, cell) {
this.dir = dir;
this.x = cell.bx;
this.y = cell.by;
},
toString: function() {
return ["DS", this.dir, this.x, this.y].join(",");
},
decode: function(strs) {
if (strs[0] !== "DS") {
return false;
}
this.dir = strs[1];
this.x = +strs[2];
this.y = +strs[3];
return true;
},
slide: function(dir, x, y) {
var shape = this.board.getc(x, y).path;
var dx = { R: 2, L: -2 }[dir] || 0;
var dy = { D: 2, U: -2 }[dir] || 0;
var set = new Set();
shape.nodes.forEach(function(node) {
for (var key in node.obj.adjborder) {
var value = node.obj.adjborder[key];
if (!value.isnull && value.line) {
set.add(value.id);
}
}
});
var ids = Array.from(set);
var sorter =
dir === "R" || dir === "D"
? function(a, b) {
return b - a;
}
: function(a, b) {
return a - b;
};
ids.sort(sorter);
for (var key in ids) {
var bd = this.board.border[ids[key]];
var next = this.board.getb(bd.bx + dx, bd.by + dy);
bd.line = 0;
next.line = 1;
this.board.modifyInfo(bd, "border.line");
bd.draw();
this.board.modifyInfo(next, "border.line");
next.draw();
}
},
undo: function() {
switch (this.dir) {
case "L":
return this.slide("R", this.x - 2, this.y);
case "R":
return this.slide("L", this.x + 2, this.y);
case "U":
return this.slide("D", this.x, this.y - 2);
case "D":
return this.slide("U", this.x, this.y + 2);
}
},
redo: function() {
return this.slide(this.dir, this.x, this.y);
},
isvalid: function() {
var shape = this.board.getc(this.x, this.y).path;
if (!shape) {
return false;
}
var dir = { U: "top", D: "bottom", L: "left", R: "right" }[this.dir];
for (var key = 0; key < shape.clist.length; key++) {
var next = shape.clist[key].adjacent[dir];
if (!next || next.isnull || (next.path && next.path !== shape)) {
return false;
}
}
return true;
}
},
OperationManager: {
addExtraOperation: function() {
this.operationlist.push(this.klass.CurveDataOperation);
this.operationlist.push(this.klass.SlideOperation);
}
},
Cell: {
minnum: 0,
maxnum: function() {
return this.board.shapes.length - 1;
},
getBits: function() {
var bits = 0;
var map = { right: 1, bottom: 2, left: 4, top: 8 };
for (var key in map) {
if (this.adjborder[key].isLine()) {
bits |= map[key];
}
}
return bits;
}
},
CellList: {
toCurveData: function() {
var rect = this.getRectSize();
var data = new this.klass.CurveData();
data.init(rect.cols, rect.rows);
for (var index = 0; index < this.length; index++) {
var cell = this[index];
var id =
((cell.by - rect.y1) / 2) * rect.cols + (cell.bx - rect.x1) / 2;
if (cell.adjborder.right.isLine()) {
data.bits[id] |= 1;
}
if (cell.adjborder.bottom.isLine()) {
data.bits[id] |= 2;
}
}
return data;
}
},
LineGraph: {
enabled: true,
makeClist: true,
invalidateClue: function(id) {
for (var i = 0; i < this.components.length; i++) {
var component = this.components[i];
if (component.isomorphicWith === id) {
component.isomorphicWith = null;
}
}
},
scanForClues: function(component) {
component.cluecnt = 0;
component.clueid = null;
for (var i = 0; i < component.nodes.length; i++) {
var cell = component.nodes[i].obj;
if (cell.qnum === -1) {
continue;
}
if (component.cluecnt === 0) {
component.cluecnt = 1;
component.clueid = cell.qnum;
} else {
component.cluecnt = 2;
component.clueid = null;
return;
}
}
},
setExtraData: function(component) {
this.common.setExtraData.call(this, component);
component.isomorphicWith = null;
component.shape = null;
this.scanForClues(component);
}
},
"Graphic@curvedata": {
irowake: true,
gridcolor_type: "LIGHT",
paint: function() {
this.drawBGCells();
this.drawDashedGrid();
this.drawPekes();
this.drawLines();
this.drawCellShapes();
this.drawHatenas();
this.drawBorders();
this.drawChassis();
this.drawTarget();
},
drawCellShapes: function() {
var g = this.vinc("cell_shape", "auto");
var clist = this.range.cells;
for (var i = 0; i < clist.length; i++) {
var cell = clist[i];
if (cell.qnum >= 0) {
var shape = this.board.shapes[cell.qnum];
if (!shape || !shape.bits.length) {
continue;
}
var w = shape.w;
var h = shape.bits.length / w;
var step = Math.min(this.bw / (w - 1), this.bh / (h - 1)) * 1.3;
var lw = Math.min(this.lw / 2, step / 4);
var dot = lw / 2;
g.lineWidth = lw;
var px = cell.bx * this.bw - (step * (w - 1)) / 2;
var py = cell.by * this.bh - (step * (h - 1)) / 2;
g.strokeStyle = "black";
g.vid = "c_shape_" + cell.id;
g.beginPath();
for (var y = 0; y < h; y++) {
for (var x = 0; x < w - 1; x++) {
if (shape.bits[y * w + x] & 1) {
g.moveTo(px + x * step - dot, py + y * step);
g.lineTo(px + (x + 1) * step + dot, py + y * step);
}
}
}
for (var y = 0; y < h - 1; y++) {
for (var x = 0; x < w; x++) {
if (shape.bits[y * w + x] & 2) {
g.moveTo(px + x * step, py + y * step - dot);
g.lineTo(px + x * step, py + (y + 1) * step + dot);
}
}
}
g.closePath();
g.stroke();
} else {
g.vid = "c_shape_" + cell.id;
g.vhide();
}
}
},
getBorderColor: function(border) {
if (
border.ques === 1 ||
border.sidecell[0].qnum === -3 ||
border.sidecell[1].qnum === -3
) {
return this.quescolor;
}
return null;
},
getBGCellColor: function(cell) {
if (cell.qnum === -3) {
return this.quescolor;
}
if (cell.error) {
return this.errbcolor1;
}
return null;
}
},
"Graphic@curvedata-aux": {
gridcolor_type: "LIGHT",
linecolor: "black",
paint: function() {
this.drawBGCells();
this.drawDashedGrid();
this.drawLines();
this.drawChassis();
}
},
BoardExec: {
adjustBoardData: function(key, d) {
if (key & this.TURNFLIP) {
var trans = this.getTranslateBits(key);
var count = this.board.shapes.length;
for (var id = 0; id < count; id++) {
var data = this.board.shapes[id];
var w = data.w;
var len = data.bits.length;
var h = len / w;
data.buildBits();
var newBits = Array(len);
for (var b = 0; b < len; b++) {
var bit = data.bits[b];
if (bit in trans) {
bit = trans[bit];
}
newBits[this.getTranslatePosition(key, w, h, b)] = bit;
}
if (key & this.TURN) {
data.w = h;
for (var y = 0; y < h; y++) {
for (var x = 0; x < w; x++) {
data.bits[x * h + y] = newBits[y * w + x];
}
}
} else {
data.bits = newBits;
}
data.invalidate();
}
if (key === this.TURNR) {
this.adjustBoardData(this.FLIPX, d);
} else if (key === this.TURNL) {
this.adjustBoardData(this.FLIPY, d);
}
}
},
getTranslatePosition: function(key, w, h, id) {
var x = Math.floor(id % w);
var y = Math.floor(id / w);
switch (key) {
case this.FLIPY:
return (h - (y + 1)) * w + x;
case this.FLIPX:
return y * w + (w - (x + 1));
default:
return id;
}
},