44d1ab16618a5ccf7599033fb9fc34efb1efd2ec
1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
, shuffle
} from "@/utils/alea";
5 export const VariantRules
= class CylinderRules
extends ChessRules
{
6 // Output basically x % 8 (circular board)
8 let res
= y
% V
.size
.y
;
14 getSlideNJumpMoves([x
, y
], steps
, oneStep
) {
16 outerLoop: for (let step
of steps
) {
18 let j
= V
.ComputeY(y
+ step
[1]);
19 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] == V
.EMPTY
) {
20 moves
.push(this.getBasicMove([x
, y
], [i
, j
]));
21 if (oneStep
!== undefined) continue outerLoop
;
23 j
= V
.ComputeY(j
+ step
[1]);
25 if (V
.OnBoard(i
, j
) && this.canTake([x
, y
], [i
, j
]))
26 moves
.push(this.getBasicMove([x
, y
], [i
, j
]));
31 getPotentialPawnMoves([x
, y
]) {
32 const color
= this.turn
;
34 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
35 const shiftX
= color
== "w" ? -1 : 1;
36 const startRank
= color
== "w" ? sizeX
- 2 : 1;
37 const lastRank
= color
== "w" ? 0 : sizeX
- 1;
40 x
+ shiftX
== lastRank
41 ? [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]
43 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
45 for (let piece
of finalPieces
) {
47 this.getBasicMove([x
, y
], [x
+ shiftX
, y
], {
55 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
58 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
62 for (let shiftY
of [-1, 1]) {
63 const nextFile
= V
.ComputeY(y
+ shiftY
);
65 this.board
[x
+ shiftX
][nextFile
] != V
.EMPTY
&&
66 this.canTake([x
, y
], [x
+ shiftX
, nextFile
])
68 for (let piece
of finalPieces
) {
70 this.getBasicMove([x
, y
], [x
+ shiftX
, nextFile
], {
80 const Lep
= this.epSquares
.length
;
81 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
84 epSquare
.x
== x
+ shiftX
&&
85 Math
.abs( (epSquare
.y
- y
) % V
.size
.y
) == 1
87 let enpassantMove
= this.getBasicMove([x
, y
], [epSquare
.x
, epSquare
.y
]);
88 enpassantMove
.vanish
.push({
92 c: this.getColor(x
, epSquare
.y
)
94 moves
.push(enpassantMove
);
100 isAttackedByPawn([x
, y
], color
) {
101 let pawnShift
= (color
== "w" ? 1 : -1);
102 if (x
+ pawnShift
>= 0 && x
+ pawnShift
< V
.size
.x
) {
103 for (let i
of [-1, 1]) {
104 const nextFile
= V
.ComputeY(y
+ i
);
106 this.getPiece(x
+ pawnShift
, nextFile
) == V
.PAWN
&&
107 this.getColor(x
+ pawnShift
, nextFile
) == color
116 isAttackedBySlideNJump([x
, y
], color
, piece
, steps
, oneStep
) {
117 for (let step
of steps
) {
118 let rx
= x
+ step
[0],
119 ry
= V
.ComputeY(y
+ step
[1]);
120 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
122 ry
= V
.ComputeY(ry
+ step
[1]);
126 this.getPiece(rx
, ry
) == piece
&&
127 this.getColor(rx
, ry
) == color
135 static get SEARCH_DEPTH() {
139 static get VALUES() {