Early draft of Wildebeest + Grand
[vchess.git] / public / javascripts / variants / Grand.js
CommitLineData
a37076f1
BA
1//https://www.chessvariants.com/large.dir/freeling.html
2class GrandRules extends ChessRules
3{
4 static getPpath(b)
5 {
6 const V = VariantRules;
7 return ([V.CAMEL,V.WILDEBEEST].includes(b[1]) ? "Grand/" : "") + b;
8 }
9
10 static get MARSHALL() { return 'm'; } //rook+knight
11 static get CARDINAL() { return 'c'; } //bishop+knight
12
13 // ------> pas les règles exactes, on démarre en 2 avec 1,2 ou 3 cases + enPassant comme Wildebeest
14// TODO: IN epSquares (return array), not return singleton. Easy. Adapt
15// just here for now...
16 getEpSquare(move)
17 {
18 const [sx,sy,ex] = [move.start.x,move.start.y,move.end.x];
19 if (this.getPiece(sx,sy) == VariantRules.PAWN && Math.abs(sx - ex) == 2)
20 {
21 return {
22 x: (sx + ex)/2,
23 y: sy
24 };
25 }
26 return undefined; //default
27 }
28
29 getPotentialMovesFrom([x,y])
30 {
31 switch (this.getPiece(x,y))
32 {
33 case VariantRules.MARSHALL:
34 return this.getPotentialMarshallMoves([x,y]);
35 case VariantRules.CARDINAL:
36 return this.getPotentialCardinalMoves([x,y]);
37 default:
38 return super.getPotentialMovesFrom([x,y])
39 }
40 }
41
42 // TODO: quite many changes! Especially promotions, only to friendly pieces already captured. ==> keep track of captured material in initVariables()......
43 getPotentialPawnMoves([x,y])
44 {
45 }
46
47 getPotentialMarshallMoves(sq)
48 {
49 const V = VariantRules;
50 return this.getSlideNJumpMoves(sq, V.steps[V.ROOK]).concat(
51 this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT], "oneStep"));
52 }
53
54 getPotentialCardinalMoves(sq)
55 {
56 const V = VariantRules;
57 return this.getSlideNJumpMoves(sq, V.steps[V.BISHOP]).concat(
58 this.getSlideNJumpMoves(sq, V.steps[V.KNIGHT], "oneStep"));
59 }
60
61 isAttacked(sq, colors)
62 {
63 return (super.isAttacked(sq, colors)
64 || this.isAttackedByMarshall(sq, colors)
65 || this.isAttackedByCardinal(sq, colors);
66 }
67
68 isAttackedByMarshall(sq, colors)
69 {
70 const V = VariantRules;
71 return this.isAttackedBySlideNJump(sq, colors, V.MARSHALL, V.steps[V.ROOK])
72 || this.isAttackedBySlideNJump(sq, colors, V.MARSHALL, V.steps[V.KNIGHT], "oneStep");
73 }
74
75 isAttackedByCardinal(sq, colors)
76 {
77 const V = VariantRules;
78 return this.isAttackedBySlideNJump(sq, colors, V.CARDINAL, V.steps[V.BISHOP])
79 || this.isAttackedBySlideNJump(sq, colors, V.CARDINAL, V.steps[V.KNIGHT], "oneStep");
80 }
81
82 static get VALUES() {
83 return Object.assign(
84 ChessRules.VALUES,
85 {'c': 5, 'm': 7} //experimental
86 );
87 }
88
89 // TODO:
90 static GenRandInitFen()
91 {
92 }
93}