6a66a068d4542e789a969206f328680d48895b48
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'], {diffCol: ['b']});
48 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
49 s
.w
.join("").toUpperCase(),
55 let parts
= super.getPartFen(o
);
56 const cmoveFen
= o
.init
|| !this.cmove
58 : C
.CoordsToSquare(this.cmove
.start
) + C
.CoordsToSquare(this.cmove
.end
);
59 parts
["cmove"] = cmoveFen
;
63 getBasicMove([sx
, sy
], [ex
, ey
]) {
64 let move = super.getBasicMove([sx
, sy
], [ex
, ey
]);
65 if (move.vanish
.length
== 2) {
79 return this.getPiece(x
, y
) != 'k' && super.canIplay(x
, y
);
82 // Does m2 un-do m1 ? (to disallow undoing captures)
83 oppositeMoves(m1
, m2
) {
86 m2
.vanish
.length
== 2 &&
87 m1
.start
.x
== m2
.start
.x
&&
88 m1
.end
.x
== m2
.end
.x
&&
89 m1
.start
.y
== m2
.start
.y
&&
95 return moves
.filter(m
=> !this.oppositeMoves(this.cmove
, m
));
101 (move.vanish
.length
== 2 ? {start: move.start
, end: move.end
} : null);
109 const color
= this.turn
;
110 const kingPos
= super.searchKingPos(color
);
111 if (color
== "w" && kingPos
[0][0] == 0) return "0-1";
112 if (color
== "b" && kingPos
[0][0] == this.size
.x
- 1) return "1-0";
113 // King is not on the opposite edge: game not over
117 // Better animation for swaps
118 customAnimate(move, segments
, cb
) {
119 if (move.vanish
.length
< 2)
121 super.animateMoving(move.end
, move.start
, null,
122 segments
.reverse().map(s
=> s
.reverse()), cb
);