1 class WildebeestRules
extends ChessRules
5 return ([V
.CAMEL
,V
.WILDEBEEST
].includes(b
[1]) ? "Wildebeest/" : "") + b
;
8 static get size() { return {x:10,y:11}; }
10 static get CAMEL() { return 'c'; }
11 static get WILDEBEEST() { return 'w'; }
14 return ChessRules
.PIECES
.concat([V
.CAMEL
,V
.WILDEBEEST
]);
19 ChessRules
.steps
, //add camel moves:
20 {'c': [ [-3,-1],[-3,1],[-1,-3],[-1,3],[1,-3],[1,3],[3,-1],[3,1] ]}
24 // En-passant after 2-sq or 3-sq jumps
27 const [sx
,sy
,ex
] = [move.start
.x
,move.start
.y
,move.end
.x
];
28 if (this.getPiece(sx
,sy
) == V
.PAWN
&& Math
.abs(sx
- ex
) >= 2)
30 const step
= (ex
-sx
) / Math
.abs(ex
-sx
);
35 if (sx
+ 2*step
!= ex
) //3-squares move
44 return undefined; //default
47 getPotentialMovesFrom([x
,y
])
49 switch (this.getPiece(x
,y
))
52 return this.getPotentialCamelMoves([x
,y
]);
54 return this.getPotentialWildebeestMoves([x
,y
]);
56 return super.getPotentialMovesFrom([x
,y
])
60 // Pawns jump 2 or 3 squares, and promote to queen or wildebeest
61 getPotentialPawnMoves([x
,y
])
63 const color
= this.turn
;
65 const [sizeX
,sizeY
] = [V
.size
.x
,V
.size
.y
];
66 const shift
= (color
== "w" ? -1 : 1);
67 const startRanks
= (color
== "w" ? [sizeX
-2,sizeX
-3] : [1,2]);
68 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
70 if (x
+shift
>= 0 && x
+shift
< sizeX
&& x
+shift
!= lastRank
)
73 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
75 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
]));
76 if (startRanks
.includes(x
) && this.board
[x
+2*shift
][y
] == V
.EMPTY
)
79 moves
.push(this.getBasicMove([x
,y
], [x
+2*shift
,y
]));
80 if (x
== startRanks
[0] && this.board
[x
+3*shift
][y
] == V
.EMPTY
)
83 moves
.push(this.getBasicMove([x
,y
], [x
+3*shift
,y
]));
88 if (y
>0 && this.canTake([x
,y
], [x
+shift
,y
-1])
89 && this.board
[x
+shift
][y
-1] != V
.EMPTY
)
91 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1]));
93 if (y
<sizeY
-1 && this.canTake([x
,y
], [x
+shift
,y
+1])
94 && this.board
[x
+shift
][y
+1] != V
.EMPTY
)
96 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1]));
100 if (x
+shift
== lastRank
)
103 let promotionPieces
= [V
.QUEEN
,V
.WILDEBEEST
];
104 promotionPieces
.forEach(p
=> {
106 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
107 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:p
}));
109 if (y
>0 && this.canTake([x
,y
], [x
+shift
,y
-1])
110 && this.board
[x
+shift
][y
-1] != V
.EMPTY
)
112 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:p
}));
114 if (y
<sizeY
-1 && this.canTake([x
,y
], [x
+shift
,y
+1])
115 && this.board
[x
+shift
][y
+1] != V
.EMPTY
)
117 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:p
}));
123 const Lep
= this.epSquares
.length
;
124 const epSquare
= Lep
>0 ? this.epSquares
[Lep
-1] : undefined;
127 for (let epsq
of epSquare
)
129 // TODO: some redundant checks
130 if (epsq
.x
== x
+shift
&& Math
.abs(epsq
.y
- y
) == 1)
132 let epStep
= epsq
.y
- y
;
133 var enpassantMove
= this.getBasicMove([x
,y
], [x
+shift
,y
+epStep
]);
134 enpassantMove
.vanish
.push({
138 c: this.getColor(x
,y
+epStep
)
140 moves
.push(enpassantMove
);
148 // TODO: wildebeest castle
150 getPotentialCamelMoves(sq
)
152 return this.getSlideNJumpMoves(sq
, V
.steps
[V
.CAMEL
], "oneStep");
155 getPotentialWildebeestMoves(sq
)
157 return this.getSlideNJumpMoves(
158 sq
, V
.steps
[V
.KNIGHT
].concat(V
.steps
[V
.CAMEL
]), "oneStep");
161 isAttacked(sq
, colors
)
163 return super.isAttacked(sq
, colors
)
164 || this.isAttackedByCamel(sq
, colors
)
165 || this.isAttackedByWildebeest(sq
, colors
);
168 isAttackedByCamel(sq
, colors
)
170 return this.isAttackedBySlideNJump(sq
, colors
,
171 V
.CAMEL
, V
.steps
[V
.CAMEL
], "oneStep");
174 isAttackedByWildebeest(sq
, colors
)
176 return this.isAttackedBySlideNJump(sq
, colors
, V
.WILDEBEEST
,
177 V
.steps
[V
.KNIGHT
].concat(V
.steps
[V
.CAMEL
]), "oneStep");
182 // No valid move: game is lost (stalemate is a win)
183 return this.turn
== "w" ? "0-1" : "1-0";
186 static get VALUES() {
187 return Object
.assign(
189 {'c': 3, 'w': 7} //experimental
193 static get SEARCH_DEPTH() { return 2; }
195 static GenRandInitFen()
197 let pieces
= { "w": new Array(10), "b": new Array(10) };
198 for (let c
of ["w","b"])
200 let positions
= _
.range(11);
202 // Get random squares for bishops + camels (different colors)
203 let randIndexes
= _
.sample(_
.range(6), 2).map(i
=> { return 2*i
; });
204 let bishop1Pos
= positions
[randIndexes
[0]];
205 let camel1Pos
= positions
[randIndexes
[1]];
206 // The second bishop (camel) must be on a square of different color
207 let randIndexes_tmp
= _
.sample(_
.range(5), 2).map(i
=> { return 2*i
+1; });
208 let bishop2Pos
= positions
[randIndexes_tmp
[0]];
209 let camel2Pos
= positions
[randIndexes_tmp
[1]];
210 for (let idx
of randIndexes
.concat(randIndexes_tmp
)
211 .sort((a
,b
) => { return b
-a
; })) //largest indices first
213 positions
.splice(idx
, 1);
216 let randIndex
= _
.random(6);
217 let knight1Pos
= positions
[randIndex
];
218 positions
.splice(randIndex
, 1);
219 randIndex
= _
.random(5);
220 let knight2Pos
= positions
[randIndex
];
221 positions
.splice(randIndex
, 1);
223 randIndex
= _
.random(4);
224 let queenPos
= positions
[randIndex
];
225 positions
.splice(randIndex
, 1);
227 // Random square for wildebeest
228 randIndex
= _
.random(3);
229 let wildebeestPos
= positions
[randIndex
];
230 positions
.splice(randIndex
, 1);
232 let rook1Pos
= positions
[0];
233 let kingPos
= positions
[1];
234 let rook2Pos
= positions
[2];
236 pieces
[c
][rook1Pos
] = 'r';
237 pieces
[c
][knight1Pos
] = 'n';
238 pieces
[c
][bishop1Pos
] = 'b';
239 pieces
[c
][queenPos
] = 'q';
240 pieces
[c
][camel1Pos
] = 'c';
241 pieces
[c
][camel2Pos
] = 'c';
242 pieces
[c
][wildebeestPos
] = 'w';
243 pieces
[c
][kingPos
] = 'k';
244 pieces
[c
][bishop2Pos
] = 'b';
245 pieces
[c
][knight2Pos
] = 'n';
246 pieces
[c
][rook2Pos
] = 'r';
248 return pieces
["b"].join("") +
249 "/ppppppppppp/11/11/11/11/11/11/PPPPPPPPPPP/" +
250 pieces
["w"].join("").toUpperCase() +