1 import { Pandemonium2Rules
} from "@/variants/Pandemonium2";
3 export class Pandemonium1Rules
extends Pandemonium2Rules
{
5 static get PawnSpecs() {
8 Pandemonium2Rules
.PawnSpecs
,
14 return { x: 10, y: 10};
17 static IsGoodEnpassant(enpassant
) {
18 if (enpassant
!= "-") {
19 const squares
= enpassant
.split(",");
20 if (squares
.length
> 2) return false;
21 for (let sq
of squares
) {
22 if (!sq
.match(/[a-j0-9]/)) return false;
28 static GenRandInitFen(randomness
) {
29 const baseFen
= Pandemonium2Rules
.GenRandInitFen(randomness
)
30 return baseFen
.substr(0, 22) + "91/91/" + baseFen
.substr(22);
34 const L
= this.epSquares
.length
;
35 if (!this.epSquares
[L
- 1]) return "-"; //no en-passant
37 this.epSquares
[L
- 1].forEach(sq
=> {
38 res
+= V
.CoordsToSquare(sq
) + ",";
40 return res
.slice(0, -1); //remove last comma
43 getEpSquare(moveOrSquare
) {
44 if (!moveOrSquare
) return undefined;
45 if (typeof moveOrSquare
=== "string") {
46 const square
= moveOrSquare
;
47 if (square
== "-") return undefined;
49 square
.split(",").forEach(sq
=> {
50 res
.push(V
.SquareToCoords(sq
));
54 // Argument is a move:
55 const move = moveOrSquare
;
56 const [sx
, sy
, ex
] = [move.start
.x
, move.start
.y
, move.end
.x
];
57 if (this.getPiece(sx
, sy
) == V
.PAWN
&& Math
.abs(sx
- ex
) >= 2) {
58 const step
= (ex
- sx
) / Math
.abs(ex
- sx
);
63 if (sx
+ 2 * step
!= ex
) {
72 return undefined; //default
75 applyPromotions(moves
, promoted
) {
76 const lastRanks
= (this.turn
== 'w' ? [0, 1] : [V
.size
.x
- 1, V
.size
.x
]);
79 if (lastRanks
.includes(m
.start
.x
) || lastRanks
.includes(m
.end
.x
)) {
80 let pMove
= JSON
.parse(JSON
.stringify(m
));
81 pMove
.appear
[0].p
= promoted
;
82 promotions
.push(pMove
);
85 Array
.prototype.push
.apply(moves
, promotions
);
88 addPawnMoves([x1
, y1
], [x2
, y2
], moves
) {
89 const color
= this.turn
;
90 const lastRanks
= (color
== "w" ? [0, 1] : [V
.size
.x
- 1, V
.size
.x
- 2]);
91 if (!lastRanks
.includes(x2
)) {
92 moves
.push(this.getBasicMove([x1
, y1
], [x2
, y2
]));
95 let finalPieces
= [V
.GILDING
];
96 if (x2
== lastRanks
[1]) finalPieces
.push(V
.PAWN
);
97 for (let piece
of finalPieces
) {
98 const tr
= (piece
!= V
.PAWN
? { c: color
, p: piece
} : null);
99 moves
.push(this.getBasicMove([x1
, y1
], [x2
, y2
], tr
));
103 getEnpassantCaptures([x
, y
], shiftX
) {
104 const Lep
= this.epSquares
.length
;
105 const epSquare
= this.epSquares
[Lep
- 1];
108 for (let epsq
of epSquare
) {
109 // TODO: some redundant checks
110 if (epsq
.x
== x
+ shiftX
&& Math
.abs(epsq
.y
- y
) == 1) {
111 let enpassantMove
= this.getBasicMove([x
, y
], [epsq
.x
, epsq
.y
]);
112 // WARNING: the captured pawn may be diagonally behind us,
113 // if it's a 3-squares jump and we take on 1st passing square
114 const px
= this.board
[x
][epsq
.y
] != V
.EMPTY
? x : x
- shiftX
;
115 enpassantMove
.vanish
.push({
119 c: this.getColor(px
, epsq
.y
)
121 moves
.push(enpassantMove
);