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