a7639aa6fc9ef4dbcf2f19e6e04cdc8910930748
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
], colors
) {
101 for (let c
of colors
) {
102 let pawnShift
= c
== "w" ? 1 : -1;
103 if (x
+ pawnShift
>= 0 && x
+ pawnShift
< V
.size
.x
) {
104 for (let i
of [-1, 1]) {
105 const nextFile
= V
.ComputeY(y
+ i
);
107 this.getPiece(x
+ pawnShift
, nextFile
) == V
.PAWN
&&
108 this.getColor(x
+ pawnShift
, nextFile
) == c
118 isAttackedBySlideNJump([x
, y
], colors
, piece
, steps
, oneStep
) {
119 for (let step
of steps
) {
120 let rx
= x
+ step
[0],
121 ry
= V
.ComputeY(y
+ step
[1]);
122 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
124 ry
= V
.ComputeY(ry
+ step
[1]);
128 this.getPiece(rx
, ry
) === piece
&&
129 colors
.includes(this.getColor(rx
, ry
))
137 static get SEARCH_DEPTH() {
141 static get VALUES() {