gungi.js 1.0.20 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1112 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.single_sqaure_move_gen = exports.generate_moves_from_probes = exports.probe_directions = exports.isSquareOutOfBounds = exports.get_squares_around = void 0;
4
- const constants_1 = require("./constants");
5
- const helper_1 = require("./helper");
6
- const get_squares_around = (square, ignore_list) => {
7
- let squares = [];
8
- let rank = parseInt(square.split('-')[0]);
9
- let file = parseInt(square.split('-')[1]);
10
- for (let i = rank - 1; i <= rank + 1; i++) {
11
- for (let j = file - 1; j <= file + 1; j++) {
12
- let valid_square = !exports.isSquareOutOfBounds(i, j);
13
- ignore_list.forEach((item) => {
14
- valid_square =
15
- valid_square &&
16
- (i != rank + item.rank_offset || j != file + item.file_offset);
17
- });
18
- if (valid_square) {
19
- squares.push({
20
- rank: i,
21
- file: j,
22
- });
23
- }
24
- }
25
- }
26
- return squares;
27
- };
28
- exports.get_squares_around = get_squares_around;
29
- const isSquareOutOfBounds = (rank, file) => {
30
- return (isNaN(rank) ||
31
- isNaN(file) ||
32
- rank < constants_1.RANK_1 ||
33
- rank > constants_1.RANK_9 ||
34
- file < constants_1.FILE_1 ||
35
- file > constants_1.FILE_9);
36
- };
37
- exports.isSquareOutOfBounds = isSquareOutOfBounds;
38
- const probe_directions = (board, square, depth, directions) => {
39
- let rank = parseInt(square.split('-')[0]);
40
- let file = parseInt(square.split('-')[1]);
41
- let squares = [];
42
- let found = Array(8).fill(false);
43
- let probes = Array(8).fill(null);
44
- for (let i = 1; i <= depth; i++) {
45
- probes.splice(0, 0, {
46
- rank: rank,
47
- file: file + i,
48
- });
49
- probes.splice(1, 0, {
50
- rank: rank,
51
- file: file - i,
52
- });
53
- probes.splice(2, 0, {
54
- rank: rank + i,
55
- file: file,
56
- });
57
- probes.splice(3, 0, {
58
- rank: rank - i,
59
- file: file,
60
- });
61
- probes.splice(4, 0, {
62
- rank: rank + i,
63
- file: file + i,
64
- });
65
- probes.splice(5, 0, {
66
- rank: rank + i,
67
- file: file - i,
68
- });
69
- probes.splice(6, 0, {
70
- rank: rank - i,
71
- file: file + i,
72
- });
73
- probes.splice(7, 0, {
74
- rank: rank - i,
75
- file: file - i,
76
- });
77
- for (let j = 0; j < 8; j++) {
78
- if (directions[j] &&
79
- !exports.isSquareOutOfBounds(probes[j].rank, probes[j].file) &&
80
- !found[j]) {
81
- squares.push(probes[j]);
82
- found[j] =
83
- helper_1.get_top(board, probes[j].rank + '-' + probes[j].file) !== null;
84
- }
85
- }
86
- }
87
- return squares;
88
- };
89
- exports.probe_directions = probe_directions;
90
- const generate_moves_from_probes = (board, probes, src, square, turn) => {
91
- let moves = [];
92
- probes.forEach((x) => {
93
- var _a, _b, _c;
94
- let pos = x.rank + '-' + x.file;
95
- let dst = helper_1.get_top(board, pos);
96
- if (dst === null) {
97
- moves.push({
98
- src: square,
99
- dst: pos,
100
- type: constants_1.MOVEMENT,
101
- });
102
- }
103
- else {
104
- if (dst.tier < 3 &&
105
- ((_a = dst.piece) === null || _a === void 0 ? void 0 : _a.type) != constants_1.MARSHAL &&
106
- ((_b = src.piece) === null || _b === void 0 ? void 0 : _b.type) != constants_1.FORTRESS) {
107
- moves.push({
108
- src: square,
109
- dst: pos,
110
- type: constants_1.STACK,
111
- });
112
- }
113
- if (((_c = dst.piece) === null || _c === void 0 ? void 0 : _c.color) !== turn) {
114
- moves.push({
115
- src: square,
116
- dst: pos,
117
- type: constants_1.ATTACK,
118
- });
119
- }
120
- }
121
- });
122
- return moves;
123
- };
124
- exports.generate_moves_from_probes = generate_moves_from_probes;
125
- const single_sqaure_move_gen = (board, src, square) => {
126
- var _a;
127
- let moves = [];
128
- let rank = parseInt(square.split('-')[0]);
129
- let file = parseInt(square.split('-')[1]);
130
- let probes = [];
131
- switch ((_a = src.piece) === null || _a === void 0 ? void 0 : _a.type) {
132
- case constants_1.MAJOR_GENERAL:
133
- switch (src.tier) {
134
- case 1:
135
- probes = [];
136
- if (src.piece.color == constants_1.BLACK) {
137
- if (!exports.isSquareOutOfBounds(rank - 1, file + 1)) {
138
- probes.push({
139
- rank: rank - 1,
140
- file: file + 1,
141
- });
142
- }
143
- if (!exports.isSquareOutOfBounds(rank - 1, file - 1)) {
144
- probes.push({
145
- rank: rank - 1,
146
- file: file - 1,
147
- });
148
- }
149
- }
150
- else {
151
- if (!exports.isSquareOutOfBounds(rank + 1, file + 1)) {
152
- probes.push({
153
- rank: rank + 1,
154
- file: file + 1,
155
- });
156
- }
157
- if (!exports.isSquareOutOfBounds(rank + 1, file - 1)) {
158
- probes.push({
159
- rank: rank + 1,
160
- file: file - 1,
161
- });
162
- }
163
- }
164
- moves = moves.concat(probes);
165
- break;
166
- case 2:
167
- probes = [];
168
- var ignore_squares_white = [
169
- {
170
- rank_offset: 0,
171
- file_offset: 0,
172
- },
173
- {
174
- rank_offset: 0,
175
- file_offset: -1,
176
- },
177
- {
178
- rank_offset: 0,
179
- file_offset: 1,
180
- },
181
- {
182
- rank_offset: -1,
183
- file_offset: 0,
184
- },
185
- ];
186
- var ignore_squares_black = [
187
- {
188
- rank_offset: 0,
189
- file_offset: 0,
190
- },
191
- {
192
- rank_offset: 0,
193
- file_offset: -1,
194
- },
195
- {
196
- rank_offset: 0,
197
- file_offset: 1,
198
- },
199
- {
200
- rank_offset: 1,
201
- file_offset: 0,
202
- },
203
- ];
204
- if (src.piece.color === constants_1.BLACK) {
205
- probes = exports.get_squares_around(square, ignore_squares_black);
206
- }
207
- else {
208
- probes = exports.get_squares_around(square, ignore_squares_white);
209
- }
210
- moves = moves.concat(probes);
211
- break;
212
- case 3:
213
- probes = [];
214
- var ignore_squares_white = [
215
- {
216
- rank_offset: 0,
217
- file_offset: 0,
218
- },
219
- {
220
- rank_offset: -1,
221
- file_offset: -1,
222
- },
223
- {
224
- rank_offset: -1,
225
- file_offset: 1,
226
- },
227
- ];
228
- var ignore_squares_black = [
229
- {
230
- rank_offset: 0,
231
- file_offset: 0,
232
- },
233
- {
234
- rank_offset: 1,
235
- file_offset: -1,
236
- },
237
- {
238
- rank_offset: 1,
239
- file_offset: 1,
240
- },
241
- ];
242
- if (src.piece.color === constants_1.BLACK) {
243
- probes = exports.get_squares_around(square, ignore_squares_black);
244
- }
245
- else {
246
- probes = exports.get_squares_around(square, ignore_squares_white);
247
- }
248
- moves = moves.concat(probes);
249
- break;
250
- }
251
- break;
252
- case constants_1.LIEUTENANT_GENERAL:
253
- switch (src.tier) {
254
- case 1:
255
- probes = [];
256
- var ignore_squares_white = [
257
- {
258
- rank_offset: 0,
259
- file_offset: 0,
260
- },
261
- {
262
- rank_offset: 0,
263
- file_offset: -1,
264
- },
265
- {
266
- rank_offset: 0,
267
- file_offset: 1,
268
- },
269
- {
270
- rank_offset: -1,
271
- file_offset: 0,
272
- },
273
- ];
274
- var ignore_squares_black = [
275
- {
276
- rank_offset: 0,
277
- file_offset: 0,
278
- },
279
- {
280
- rank_offset: 0,
281
- file_offset: -1,
282
- },
283
- {
284
- rank_offset: 0,
285
- file_offset: 1,
286
- },
287
- {
288
- rank_offset: 1,
289
- file_offset: 0,
290
- },
291
- ];
292
- if (src.piece.color === constants_1.BLACK) {
293
- probes = exports.get_squares_around(square, ignore_squares_black);
294
- }
295
- else {
296
- probes = exports.get_squares_around(square, ignore_squares_white);
297
- }
298
- moves = moves.concat(probes);
299
- break;
300
- case 2:
301
- probes = [];
302
- var ignore_squares = [
303
- {
304
- rank_offset: 0,
305
- file_offset: 0,
306
- },
307
- {
308
- rank_offset: 0,
309
- file_offset: -1,
310
- },
311
- {
312
- rank_offset: 0,
313
- file_offset: 1,
314
- },
315
- ];
316
- probes = exports.get_squares_around(square, ignore_squares);
317
- moves = moves.concat(probes);
318
- break;
319
- case 3:
320
- probes = [];
321
- var ignore_squares = [
322
- {
323
- rank_offset: 0,
324
- file_offset: 0,
325
- },
326
- ];
327
- probes = exports.get_squares_around(square, ignore_squares);
328
- moves = moves.concat(probes);
329
- break;
330
- }
331
- break;
332
- case constants_1.GENERAL:
333
- switch (src.tier) {
334
- case 1:
335
- probes = [];
336
- var ignore_squares_white = [
337
- {
338
- rank_offset: 0,
339
- file_offset: 0,
340
- },
341
- {
342
- rank_offset: -1,
343
- file_offset: -1,
344
- },
345
- {
346
- rank_offset: -1,
347
- file_offset: 1,
348
- },
349
- ];
350
- var ignore_squares_black = [
351
- {
352
- rank_offset: 0,
353
- file_offset: 0,
354
- },
355
- {
356
- rank_offset: 1,
357
- file_offset: -1,
358
- },
359
- {
360
- rank_offset: 1,
361
- file_offset: 1,
362
- },
363
- ];
364
- if (src.piece.color === constants_1.BLACK) {
365
- probes = exports.get_squares_around(square, ignore_squares_black);
366
- }
367
- else {
368
- probes = exports.get_squares_around(square, ignore_squares_white);
369
- }
370
- moves = moves.concat(probes);
371
- break;
372
- case 2:
373
- probes = [];
374
- var ignore_squares = [
375
- {
376
- rank_offset: 0,
377
- file_offset: 0,
378
- },
379
- ];
380
- probes = exports.get_squares_around(square, ignore_squares);
381
- moves = moves.concat(probes);
382
- break;
383
- case 3:
384
- probes = [];
385
- var ignore_squares = [
386
- {
387
- rank_offset: 0,
388
- file_offset: 0,
389
- },
390
- ];
391
- probes = exports.get_squares_around(square, ignore_squares);
392
- if (src.piece.color === constants_1.BLACK) {
393
- if (!exports.isSquareOutOfBounds(rank - 2, file - 1) &&
394
- !helper_1.get_top(board, rank - 1 + '-' + (file - 1))) {
395
- probes.push({
396
- rank: rank - 2,
397
- file: file - 1,
398
- });
399
- }
400
- if (!exports.isSquareOutOfBounds(rank - 2, file) &&
401
- !helper_1.get_top(board, rank - 1 + '-' + file)) {
402
- probes.push({
403
- rank: rank - 2,
404
- file: file,
405
- });
406
- }
407
- if (!exports.isSquareOutOfBounds(rank - 2, file + 1) &&
408
- !helper_1.get_top(board, rank - 1 + '-' + (file + 1))) {
409
- probes.push({
410
- rank: rank - 2,
411
- file: file + 1,
412
- });
413
- }
414
- }
415
- else {
416
- if (!exports.isSquareOutOfBounds(rank + 2, file - 1) &&
417
- !helper_1.get_top(board, rank + 1 + '-' + (file - 1))) {
418
- probes.push({
419
- rank: rank + 2,
420
- file: file - 1,
421
- });
422
- }
423
- if (!exports.isSquareOutOfBounds(rank + 2, file) &&
424
- !helper_1.get_top(board, rank + 1 + '-' + file)) {
425
- probes.push({
426
- rank: rank + 2,
427
- file: file,
428
- });
429
- }
430
- if (!exports.isSquareOutOfBounds(rank + 2, file + 1) &&
431
- !helper_1.get_top(board, rank + 1 + '-' + (file + 1))) {
432
- probes.push({
433
- rank: rank + 2,
434
- file: file + 1,
435
- });
436
- }
437
- }
438
- moves = moves.concat(probes);
439
- break;
440
- }
441
- break;
442
- case constants_1.ARCHER:
443
- switch (src.tier) {
444
- case 1:
445
- probes = [];
446
- var ignore_squares = [
447
- {
448
- rank_offset: 0,
449
- file_offset: 0,
450
- },
451
- ];
452
- probes = exports.get_squares_around(square, ignore_squares);
453
- moves = moves.concat(probes);
454
- break;
455
- case 2:
456
- probes = [];
457
- for (var i = 0; i < 4; i++) {
458
- if (!exports.isSquareOutOfBounds(rank - 2, file + 2 - i)) {
459
- probes.push({
460
- rank: rank - 2,
461
- file: file + 2 - i,
462
- });
463
- }
464
- if (!exports.isSquareOutOfBounds(rank - 2 + i, file - 2)) {
465
- probes.push({
466
- rank: rank - 2 + i,
467
- file: file - 2,
468
- });
469
- }
470
- if (!exports.isSquareOutOfBounds(rank + 2, file - 2 + i)) {
471
- probes.push({
472
- rank: rank + 2,
473
- file: file - 2 + i,
474
- });
475
- }
476
- if (!exports.isSquareOutOfBounds(rank + 2 - i, file + 2)) {
477
- probes.push({
478
- rank: rank + 2 - i,
479
- file: file + 2,
480
- });
481
- }
482
- }
483
- moves = moves.concat(probes);
484
- break;
485
- case 3:
486
- probes = [];
487
- for (var i = 0; i < 6; i++) {
488
- if (!exports.isSquareOutOfBounds(rank - 3, file + 3 - i)) {
489
- probes.push({
490
- rank: rank - 3,
491
- file: file + 3 - i,
492
- });
493
- }
494
- if (!exports.isSquareOutOfBounds(rank - 3 + i, file - 3)) {
495
- probes.push({
496
- rank: rank - 3 + i,
497
- file: file - 3,
498
- });
499
- }
500
- if (!exports.isSquareOutOfBounds(rank + 3, file - 3 + i)) {
501
- probes.push({
502
- rank: rank + 3,
503
- file: file - 3 + i,
504
- });
505
- }
506
- if (!exports.isSquareOutOfBounds(rank + 3 - i, file + 3)) {
507
- probes.push({
508
- rank: rank + 3 - i,
509
- file: file + 3,
510
- });
511
- }
512
- }
513
- moves = moves.concat(probes);
514
- break;
515
- }
516
- break;
517
- case constants_1.KNIGHT:
518
- switch (src.tier) {
519
- case 1:
520
- probes = [];
521
- if (src.piece.color === constants_1.BLACK) {
522
- if (!exports.isSquareOutOfBounds(rank, file - 1)) {
523
- probes.push({
524
- rank: rank,
525
- file: file - 1,
526
- });
527
- }
528
- if (!exports.isSquareOutOfBounds(rank, file + 1)) {
529
- probes.push({
530
- rank: rank,
531
- file: file + 1,
532
- });
533
- }
534
- if (!exports.isSquareOutOfBounds(rank - 2, file - 1)) {
535
- probes.push({
536
- rank: rank - 2,
537
- file: file - 1,
538
- });
539
- }
540
- if (!exports.isSquareOutOfBounds(rank - 2, file + 1)) {
541
- probes.push({
542
- rank: rank - 2,
543
- file: file + 1,
544
- });
545
- }
546
- }
547
- else {
548
- if (!exports.isSquareOutOfBounds(rank, file - 1)) {
549
- probes.push({
550
- rank: rank,
551
- file: file - 1,
552
- });
553
- }
554
- if (!exports.isSquareOutOfBounds(rank, file + 1)) {
555
- probes.push({
556
- rank: rank,
557
- file: file + 1,
558
- });
559
- }
560
- if (!exports.isSquareOutOfBounds(rank + 2, file - 1)) {
561
- probes.push({
562
- rank: rank + 2,
563
- file: file - 1,
564
- });
565
- }
566
- if (!exports.isSquareOutOfBounds(rank + 2, file + 1)) {
567
- probes.push({
568
- rank: rank + 2,
569
- file: file + 1,
570
- });
571
- }
572
- }
573
- moves = moves.concat(probes);
574
- break;
575
- case 2:
576
- probes = [];
577
- if (src.piece.color === constants_1.BLACK) {
578
- if (!exports.isSquareOutOfBounds(rank - 1, file - 2)) {
579
- probes.push({
580
- rank: rank - 1,
581
- file: file - 2,
582
- });
583
- }
584
- if (!exports.isSquareOutOfBounds(rank - 2, file - 1)) {
585
- probes.push({
586
- rank: rank - 2,
587
- file: file - 1,
588
- });
589
- }
590
- if (!exports.isSquareOutOfBounds(rank - 2, file + 1)) {
591
- probes.push({
592
- rank: rank - 2,
593
- file: file + 1,
594
- });
595
- }
596
- if (!exports.isSquareOutOfBounds(rank - 1, file + 2)) {
597
- probes.push({
598
- rank: rank - 1,
599
- file: file + 2,
600
- });
601
- }
602
- }
603
- else {
604
- if (!exports.isSquareOutOfBounds(rank + 1, file - 2)) {
605
- probes.push({
606
- rank: rank + 1,
607
- file: file - 2,
608
- });
609
- }
610
- if (!exports.isSquareOutOfBounds(rank + 2, file - 1)) {
611
- probes.push({
612
- rank: rank + 2,
613
- file: file - 1,
614
- });
615
- }
616
- if (!exports.isSquareOutOfBounds(rank + 2, file + 1)) {
617
- probes.push({
618
- rank: rank + 2,
619
- file: file + 1,
620
- });
621
- }
622
- if (!exports.isSquareOutOfBounds(rank + 1, file + 2)) {
623
- probes.push({
624
- rank: rank + 1,
625
- file: file + 2,
626
- });
627
- }
628
- }
629
- moves = moves.concat(probes);
630
- break;
631
- case 3:
632
- probes = [];
633
- if (!exports.isSquareOutOfBounds(rank - 1, file - 2)) {
634
- probes.push({
635
- rank: rank - 1,
636
- file: file - 2,
637
- });
638
- }
639
- if (!exports.isSquareOutOfBounds(rank - 2, file - 1)) {
640
- probes.push({
641
- rank: rank - 2,
642
- file: file - 1,
643
- });
644
- }
645
- if (!exports.isSquareOutOfBounds(rank - 2, file + 1)) {
646
- probes.push({
647
- rank: rank - 2,
648
- file: file + 1,
649
- });
650
- }
651
- if (!exports.isSquareOutOfBounds(rank - 1, file + 2)) {
652
- probes.push({
653
- rank: rank - 1,
654
- file: file + 2,
655
- });
656
- }
657
- if (!exports.isSquareOutOfBounds(rank + 1, file - 2)) {
658
- probes.push({
659
- rank: rank + 1,
660
- file: file - 2,
661
- });
662
- }
663
- if (!exports.isSquareOutOfBounds(rank + 2, file - 1)) {
664
- probes.push({
665
- rank: rank + 2,
666
- file: file - 1,
667
- });
668
- }
669
- if (!exports.isSquareOutOfBounds(rank + 2, file + 1)) {
670
- probes.push({
671
- rank: rank + 2,
672
- file: file + 1,
673
- });
674
- }
675
- if (!exports.isSquareOutOfBounds(rank + 1, file + 2)) {
676
- probes.push({
677
- rank: rank + 1,
678
- file: file + 2,
679
- });
680
- }
681
- moves = moves.concat(probes);
682
- break;
683
- }
684
- break;
685
- case constants_1.MUSKETEER:
686
- switch (src.tier) {
687
- case 1:
688
- probes = [];
689
- if (src.piece.color === constants_1.BLACK) {
690
- if (!exports.isSquareOutOfBounds(rank - 1, file)) {
691
- probes.push({
692
- rank: rank - 1,
693
- file: file,
694
- });
695
- }
696
- }
697
- else {
698
- if (!exports.isSquareOutOfBounds(rank + 1, file)) {
699
- probes.push({
700
- rank: rank + 1,
701
- file: file,
702
- });
703
- }
704
- }
705
- moves = moves.concat(probes);
706
- break;
707
- case 2:
708
- if (src.piece.color === constants_1.BLACK) {
709
- probes = exports.probe_directions(board, square, 2, [
710
- false,
711
- false,
712
- false,
713
- true,
714
- false,
715
- false,
716
- false,
717
- false,
718
- ]);
719
- moves = moves.concat(probes);
720
- }
721
- else {
722
- probes = exports.probe_directions(board, square, 2, [
723
- false,
724
- false,
725
- true,
726
- false,
727
- false,
728
- false,
729
- false,
730
- false,
731
- ]);
732
- moves = moves.concat(probes);
733
- }
734
- break;
735
- case 3:
736
- if (src.piece.color === constants_1.BLACK) {
737
- probes = exports.probe_directions(board, square, 8, [
738
- false,
739
- false,
740
- false,
741
- true,
742
- false,
743
- false,
744
- false,
745
- false,
746
- ]);
747
- moves = moves.concat(probes);
748
- }
749
- else {
750
- probes = exports.probe_directions(board, square, 8, [
751
- false,
752
- false,
753
- true,
754
- false,
755
- false,
756
- false,
757
- false,
758
- false,
759
- ]);
760
- moves = moves.concat(probes);
761
- }
762
- break;
763
- }
764
- break;
765
- case constants_1.CAPTAIN:
766
- switch (src.tier) {
767
- case 1:
768
- probes = [];
769
- var ignore_squares = [
770
- {
771
- rank_offset: 0,
772
- file_offset: 0,
773
- },
774
- ];
775
- probes = exports.get_squares_around(square, ignore_squares);
776
- moves = moves.concat(probes);
777
- break;
778
- case 2:
779
- case 3:
780
- var piece_under = helper_1.get(board, square)[src.tier - 2];
781
- if (piece_under) {
782
- if (piece_under.type === constants_1.CAPTAIN) {
783
- var deep_piece_under = helper_1.get(board, square)[src.tier - 3];
784
- if (deep_piece_under) {
785
- moves = moves.concat(exports.single_sqaure_move_gen(board, {
786
- piece: {
787
- type: deep_piece_under.type,
788
- color: src.piece.color,
789
- },
790
- tier: src.tier,
791
- }, square));
792
- }
793
- else {
794
- probes = [];
795
- var ignore_squares = [
796
- {
797
- rank_offset: 0,
798
- file_offset: 0,
799
- },
800
- ];
801
- probes = exports.get_squares_around(square, ignore_squares);
802
- moves = moves.concat(probes);
803
- }
804
- }
805
- else {
806
- moves = moves.concat(exports.single_sqaure_move_gen(board, {
807
- piece: { type: piece_under.type, color: src.piece.color },
808
- tier: src.tier,
809
- }, square));
810
- }
811
- }
812
- break;
813
- }
814
- break;
815
- case constants_1.SAMURAI:
816
- switch (src.tier) {
817
- case 1:
818
- probes = [];
819
- if (!exports.isSquareOutOfBounds(rank + 1, file - 1)) {
820
- probes.push({
821
- rank: rank + 1,
822
- file: file - 1,
823
- });
824
- }
825
- if (!exports.isSquareOutOfBounds(rank + 1, file + 1)) {
826
- probes.push({
827
- rank: rank + 1,
828
- file: file + 1,
829
- });
830
- }
831
- if (!exports.isSquareOutOfBounds(rank - 1, file - 1)) {
832
- probes.push({
833
- rank: rank - 1,
834
- file: file - 1,
835
- });
836
- }
837
- if (!exports.isSquareOutOfBounds(rank - 1, file + 1)) {
838
- probes.push({
839
- rank: rank - 1,
840
- file: file + 1,
841
- });
842
- }
843
- moves = moves.concat(probes);
844
- break;
845
- case 2:
846
- probes = [];
847
- if (!exports.isSquareOutOfBounds(rank + 2, file - 2)) {
848
- probes.push({
849
- rank: rank + 2,
850
- file: file - 2,
851
- });
852
- }
853
- if (!exports.isSquareOutOfBounds(rank + 2, file + 2)) {
854
- probes.push({
855
- rank: rank + 2,
856
- file: file + 2,
857
- });
858
- }
859
- if (!exports.isSquareOutOfBounds(rank - 2, file - 2)) {
860
- probes.push({
861
- rank: rank - 2,
862
- file: file - 2,
863
- });
864
- }
865
- if (!exports.isSquareOutOfBounds(rank - 2, file + 2)) {
866
- probes.push({
867
- rank: rank - 2,
868
- file: file + 2,
869
- });
870
- }
871
- moves = moves.concat(probes);
872
- break;
873
- case 3:
874
- probes = exports.probe_directions(board, square, 8, [
875
- false,
876
- false,
877
- false,
878
- false,
879
- true,
880
- true,
881
- true,
882
- true,
883
- ]);
884
- moves = moves.concat(probes);
885
- break;
886
- }
887
- break;
888
- case constants_1.FORTRESS:
889
- probes = [];
890
- var ignore_squares = [
891
- {
892
- rank_offset: 0,
893
- file_offset: 0,
894
- },
895
- ];
896
- probes = exports.get_squares_around(square, ignore_squares);
897
- moves = moves.concat(probes);
898
- break;
899
- case constants_1.CANNON:
900
- switch (src.tier) {
901
- case 1:
902
- probes = [];
903
- if (!exports.isSquareOutOfBounds(rank, file - 1)) {
904
- probes.push({
905
- rank: rank,
906
- file: file - 1,
907
- });
908
- }
909
- if (!exports.isSquareOutOfBounds(rank, file + 1)) {
910
- probes.push({
911
- rank: rank,
912
- file: file + 1,
913
- });
914
- }
915
- if (!exports.isSquareOutOfBounds(rank - 1, file)) {
916
- probes.push({
917
- rank: rank - 1,
918
- file: file,
919
- });
920
- }
921
- if (!exports.isSquareOutOfBounds(rank + 1, file)) {
922
- probes.push({
923
- rank: rank + 1,
924
- file: file,
925
- });
926
- }
927
- moves = moves.concat(probes);
928
- break;
929
- case 2:
930
- probes = exports.probe_directions(board, square, 2, [
931
- true,
932
- true,
933
- true,
934
- true,
935
- false,
936
- false,
937
- false,
938
- false,
939
- ]);
940
- moves = moves.concat(probes);
941
- break;
942
- case 3:
943
- probes = exports.probe_directions(board, square, 8, [
944
- true,
945
- true,
946
- true,
947
- true,
948
- false,
949
- false,
950
- false,
951
- false,
952
- ]);
953
- moves = moves.concat(probes);
954
- break;
955
- }
956
- break;
957
- case constants_1.SPY:
958
- switch (src.tier) {
959
- case 1:
960
- probes = [];
961
- if (src.piece.color === constants_1.BLACK) {
962
- if (!exports.isSquareOutOfBounds(rank - 1, file)) {
963
- probes.push({
964
- rank: rank - 1,
965
- file: file,
966
- });
967
- }
968
- }
969
- else {
970
- if (!exports.isSquareOutOfBounds(rank + 1, file)) {
971
- probes.push({
972
- rank: rank + 1,
973
- file: file,
974
- });
975
- }
976
- }
977
- moves = moves.concat(probes);
978
- break;
979
- case 2:
980
- probes = [];
981
- if (!exports.isSquareOutOfBounds(rank + 1, file - 1)) {
982
- probes.push({
983
- rank: rank + 1,
984
- file: file - 1,
985
- });
986
- }
987
- if (!exports.isSquareOutOfBounds(rank + 1, file + 1)) {
988
- probes.push({
989
- rank: rank + 1,
990
- file: file + 1,
991
- });
992
- }
993
- if (!exports.isSquareOutOfBounds(rank - 1, file - 1)) {
994
- probes.push({
995
- rank: rank - 1,
996
- file: file - 1,
997
- });
998
- }
999
- if (!exports.isSquareOutOfBounds(rank - 1, file + 1)) {
1000
- probes.push({
1001
- rank: rank - 1,
1002
- file: file + 1,
1003
- });
1004
- }
1005
- moves = moves.concat(probes);
1006
- break;
1007
- case 3:
1008
- probes = exports.probe_directions(board, square, 8, [
1009
- true,
1010
- true,
1011
- true,
1012
- true,
1013
- true,
1014
- true,
1015
- true,
1016
- true,
1017
- ]);
1018
- moves = moves.concat(probes);
1019
- break;
1020
- }
1021
- break;
1022
- case constants_1.PAWN:
1023
- switch (src.tier) {
1024
- case 1:
1025
- probes = [];
1026
- if (src.piece.color === constants_1.BLACK) {
1027
- if (!exports.isSquareOutOfBounds(rank - 1, file)) {
1028
- probes.push({
1029
- rank: rank - 1,
1030
- file: file,
1031
- });
1032
- }
1033
- }
1034
- else {
1035
- if (!exports.isSquareOutOfBounds(rank + 1, file)) {
1036
- probes.push({
1037
- rank: rank + 1,
1038
- file: file,
1039
- });
1040
- }
1041
- }
1042
- moves = moves.concat(probes);
1043
- break;
1044
- case 2:
1045
- case 3:
1046
- probes = [];
1047
- if (src.piece.color === constants_1.BLACK) {
1048
- if (!exports.isSquareOutOfBounds(rank - 1, file)) {
1049
- probes.push({
1050
- rank: rank - 1,
1051
- file: file,
1052
- });
1053
- }
1054
- if (!exports.isSquareOutOfBounds(rank - 1, file - 1)) {
1055
- probes.push({
1056
- rank: rank - 1,
1057
- file: file - 1,
1058
- });
1059
- }
1060
- if (!exports.isSquareOutOfBounds(rank - 1, file + 1)) {
1061
- probes.push({
1062
- rank: rank - 1,
1063
- file: file + 1,
1064
- });
1065
- }
1066
- }
1067
- else {
1068
- if (!exports.isSquareOutOfBounds(rank + 1, file)) {
1069
- probes.push({
1070
- rank: rank + 1,
1071
- file: file,
1072
- });
1073
- }
1074
- if (!exports.isSquareOutOfBounds(rank + 1, file - 1)) {
1075
- probes.push({
1076
- rank: rank + 1,
1077
- file: file - 1,
1078
- });
1079
- }
1080
- if (!exports.isSquareOutOfBounds(rank + 1, file + 1)) {
1081
- probes.push({
1082
- rank: rank + 1,
1083
- file: file + 1,
1084
- });
1085
- }
1086
- }
1087
- moves = moves.concat(probes);
1088
- break;
1089
- }
1090
- break;
1091
- case constants_1.MARSHAL:
1092
- switch (src.tier) {
1093
- case 1:
1094
- case 2:
1095
- case 3:
1096
- probes = [];
1097
- var ignore_squares = [
1098
- {
1099
- rank_offset: 0,
1100
- file_offset: 0,
1101
- },
1102
- ];
1103
- probes = exports.get_squares_around(square, ignore_squares);
1104
- moves = moves.concat(probes);
1105
- break;
1106
- }
1107
- break;
1108
- }
1109
- return moves;
1110
- };
1111
- exports.single_sqaure_move_gen = single_sqaure_move_gen;
1112
- //# sourceMappingURL=move_gen.js.map