ff307d4a3d4cde9e5d76255b5e36f7d27c30d63e
1 import ChessRules
from "/base_rules.js";
2 import {FenUtil
} from "/utils/setupPieces.js";
3 import PiPo
from "/utils/PiPo.js";
4 import Move
from "/utils/Move.js";
6 export default class SuctionRules
extends ChessRules
{
10 select: C
.Options
.select
,
24 get pawnPromotions() {
25 return ['p']; //no promotions
32 setOtherVariables(fenParsed
) {
33 super.setOtherVariables(fenParsed
);
35 const cmove_str
= fenParsed
.cmove
;
36 if (cmove_str
!= "-") {
38 start: C
.SquareToCoords(cmove_str
.substr(0, 2)),
39 end: C
.SquareToCoords(cmove_str
.substr(2))
44 genRandInitBaseFen() {
45 const s
= FenUtil
.setupPieces(
46 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'],
48 randomness: this.options
["randomness"],
53 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
54 s
.w
.join("").toUpperCase(),
60 let parts
= super.getPartFen(o
);
61 const cmoveFen
= o
.init
|| !this.cmove
63 : C
.CoordsToSquare(this.cmove
.start
) + C
.CoordsToSquare(this.cmove
.end
);
64 parts
["cmove"] = cmoveFen
;
68 getBasicMove([sx
, sy
], [ex
, ey
]) {
69 let move = super.getBasicMove([sx
, sy
], [ex
, ey
]);
70 if (move.vanish
.length
== 2) {
84 return this.getPiece(x
, y
) != 'k' && super.canIplay(x
, y
);
87 // Does m2 un-do m1 ? (to disallow undoing captures)
88 oppositeMoves(m1
, m2
) {
91 m2
.vanish
.length
== 2 &&
92 m1
.start
.x
== m2
.start
.x
&&
93 m1
.end
.x
== m2
.end
.x
&&
94 m1
.start
.y
== m2
.start
.y
&&
100 return moves
.filter(m
=> !this.oppositeMoves(this.cmove
, m
));
104 super.postPlay(move);
106 (move.vanish
.length
== 2 ? {start: move.start
, end: move.end
} : null);
114 const color
= this.turn
;
115 const kingPos
= super.searchKingPos(color
);
116 if (color
== "w" && kingPos
[0][0] == 0) return "0-1";
117 if (color
== "b" && kingPos
[0][0] == this.size
.x
- 1) return "1-0";
118 // King is not on the opposite edge: game not over
122 // Better animation for swaps
123 customAnimate(move, segments
, cb
) {
124 if (move.vanish
.length
< 2)
126 super.animateMoving(move.end
, move.start
, null,
127 segments
.reverse().map(s
=> s
.reverse()), cb
);