Some improvements. Testing variants: Baroque has some issues
[xogo.git] / variants / Balaklava / class.js
CommitLineData
33b42748 1import ChessRules from "/base_rules.js";
7c038235 2import {FenUtil} from "/utils/setupPieces.js";
33b42748
BA
3
4export default class BalaklavaRules extends ChessRules {
5
6 get pawnPromotions() {
7 return ['r', 'm', 'b', 'q'];
8 }
9
10 get hasEnpassant() {
11 return false;
12 }
13
14 pieces(color, x, y) {
15 let res = super.pieces(color, x, y);
bc97fdd1 16 const knightSpecMoves = res['n'].both;
33b42748
BA
17 delete res['n'];
18 res['m'] = {
19 "class": "mammoth",
20 both: [
21 {
22 steps: [
23 [-2, -2], [-2, 0], [-2, 2],
24 [0, -2], [0, 2], [2, -2],
25 [2, 0], [2, 2]
26 ],
27 range: 1
28 }
29 ]
30 };
bc97fdd1
BA
31 ['p', 'r', 'b', 'm', 'q'].forEach(p => {
32 if (!res[p].moves)
33 res[p].moves = [];
34 Array.prototype.push.apply(res[p].moves, knightSpecMoves);
35 });
33b42748
BA
36 return res;
37 }
38
39 genRandInitBaseFen() {
7c038235 40 const s = FenUtil.setupPieces(
10c9010b
BA
41 ['r', 'm', 'b', 'q', 'k', 'b', 'm', 'r'],
42 {
43 randomness: this.options["randomness"],
44 diffCol: ['b']
45 }
46 );
33b42748 47 return {
7c038235
BA
48 fen: s.b.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
49 s.w.join("").toUpperCase(),
bc97fdd1 50 o: {flags: s.flags}
33b42748
BA
51 };
52 }
53
54 pawnPostProcess(moves) {
55 if (moves.length == 0)
56 return [];
57 const color = moves[0].vanish[0].c;
58 const lastRank = (color == 'w' ? 0 : this.size.x - 1);
0437a28b 59 const forward = (color == 'w' ? -1 : 1);
33b42748
BA
60 const noKnightPromotions = moves.filter(m => {
61 return (
0437a28b 62 (m.end.x - m.start.x) * forward > 0 &&
33b42748 63 (
0437a28b
BA
64 m.end.x != lastRank ||
65 (
66 Math.abs(m.start.x - m.end.x) <= 1 &&
67 Math.abs(m.start.y - m.end.y) <= 1
68 )
33b42748
BA
69 )
70 );
71 });
72 return super.pawnPostProcess(noKnightPromotions);
73 }
74
75};