e2e36c866ba9bda5d8a51a12b0bbb814bc2f5a17
1 import ChessRules
from "/base_rules.js";
2 import GiveawayRules
from "/variants/Giveaway/class.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 genRandInitFen(seed
) {
45 const options
= Object
.assign({mode: "suicide"}, this.options
);
46 const gr
= new GiveawayRules({options: options
, genFenOnly: true});
49 gr
.genRandInitFen(seed
).slice(0, -17) + '{"enpassant":"-","cmove":"-"}');
53 const cmoveFen
= !this.cmove
55 : C
.CoordsToSquare(this.cmove
.start
) + C
.CoordsToSquare(this.cmove
.end
);
56 return super.getFen().slice(0, -1) + ',"cmove":"' + cmoveFen
+ '"}';
59 getBasicMove([sx
, sy
], [ex
, ey
]) {
60 let move = super.getBasicMove([sx
, sy
], [ex
, ey
]);
61 if (move.vanish
.length
== 2) {
75 return this.getPiece(x
, y
) != 'k' && super.canIplay(x
, y
);
78 // Does m2 un-do m1 ? (to disallow undoing captures)
79 oppositeMoves(m1
, m2
) {
82 m2
.vanish
.length
== 2 &&
83 m1
.start
.x
== m2
.start
.x
&&
84 m1
.end
.x
== m2
.end
.x
&&
85 m1
.start
.y
== m2
.start
.y
&&
91 return moves
.filter(m
=> !this.oppositeMoves(this.cmove
, m
));
97 (move.vanish
.length
== 2 ? {start: move.start
, end: move.end
} : null);
105 const color
= this.turn
;
106 const kingPos
= super.searchKingPos(color
);
107 if (color
== "w" && kingPos
[0] == 0) return "0-1";
108 if (color
== "b" && kingPos
[0] == this.size
.x
- 1) return "1-0";
109 // King is not on the opposite edge: game not over