1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
2 import { ArrayFun
} from "@/utils/array";
3 import { randInt
, shuffle
} from "@/utils/alea";
5 export 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 // Don't add move twice when running on an infinite rank:
17 let infiniteSteps
= {};
18 outerLoop: for (let step
of steps
) {
19 if (!!infiniteSteps
[(-step
[0]) + "." + (-step
[1])]) continue;
21 let j
= V
.ComputeY(y
+ step
[1]);
22 while (V
.OnBoard(i
, j
) && this.board
[i
][j
] == V
.EMPTY
) {
23 moves
.push(this.getBasicMove([x
, y
], [i
, j
]));
24 if (oneStep
!== undefined) continue outerLoop
;
26 j
= V
.ComputeY(j
+ step
[1]);
28 if (V
.OnBoard(i
, j
)) {
30 // Looped back onto initial square
31 infiniteSteps
[step
[0] + "." + step
[1]] = true;
32 else if (this.canTake([x
, y
], [i
, j
]))
33 moves
.push(this.getBasicMove([x
, y
], [i
, j
]));
39 getPotentialPawnMoves([x
, y
]) {
40 const color
= this.turn
;
42 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
43 const shiftX
= color
== "w" ? -1 : 1;
44 const startRank
= color
== "w" ? sizeX
- 2 : 1;
45 const lastRank
= color
== "w" ? 0 : sizeX
- 1;
48 x
+ shiftX
== lastRank
49 ? [V
.ROOK
, V
.KNIGHT
, V
.BISHOP
, V
.QUEEN
]
51 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
53 for (let piece
of finalPieces
) {
55 this.getBasicMove([x
, y
], [x
+ shiftX
, y
], {
63 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
66 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
70 for (let shiftY
of [-1, 1]) {
71 const nextFile
= V
.ComputeY(y
+ shiftY
);
73 this.board
[x
+ shiftX
][nextFile
] != V
.EMPTY
&&
74 this.canTake([x
, y
], [x
+ shiftX
, nextFile
])
76 for (let piece
of finalPieces
) {
78 this.getBasicMove([x
, y
], [x
+ shiftX
, nextFile
], {
88 const Lep
= this.epSquares
.length
;
89 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
92 epSquare
.x
== x
+ shiftX
&&
93 Math
.abs( (epSquare
.y
- y
) % V
.size
.y
) == 1
95 let enpassantMove
= this.getBasicMove([x
, y
], [epSquare
.x
, epSquare
.y
]);
96 enpassantMove
.vanish
.push({
100 c: this.getColor(x
, epSquare
.y
)
102 moves
.push(enpassantMove
);
108 isAttackedByPawn([x
, y
], color
) {
109 let pawnShift
= (color
== "w" ? 1 : -1);
110 if (x
+ pawnShift
>= 0 && x
+ pawnShift
< V
.size
.x
) {
111 for (let i
of [-1, 1]) {
112 const nextFile
= V
.ComputeY(y
+ i
);
114 this.getPiece(x
+ pawnShift
, nextFile
) == V
.PAWN
&&
115 this.getColor(x
+ pawnShift
, nextFile
) == color
124 isAttackedBySlideNJump([x
, y
], color
, piece
, steps
, oneStep
) {
125 for (let step
of steps
) {
126 let rx
= x
+ step
[0],
127 ry
= V
.ComputeY(y
+ step
[1]);
128 while (V
.OnBoard(rx
, ry
) && this.board
[rx
][ry
] == V
.EMPTY
&& !oneStep
) {
130 ry
= V
.ComputeY(ry
+ step
[1]);
134 this.getPiece(rx
, ry
) == piece
&&
135 this.getColor(rx
, ry
) == color
143 static get SEARCH_DEPTH() {
147 static get VALUES() {