+ // Circular?
+ getX(x) {
+ return x; //generally, no
+ }
+
+ increment([x, y], step) {
+ return [
+ this.getX(x + step[0]),
+ this.getY(y + step[1])
+ ];
+ }
+
+ getSegments(curSeg, segStart, segEnd) {
+ if (curSeg.length == 0)
+ return undefined;
+ let segments = JSON.parse(JSON.stringify(curSeg)); //not altering
+ segments.push([[segStart[0], segStart[1]], [segEnd[0], segEnd[1]]]);
+ return segments;
+ }
+
+ getStepSpec(color, x, y, piece) {
+ let pieceType = piece;
+ let allSpecs = this.pieces(color, x, y);
+ if (!piece)
+ pieceType = this.getPieceType(x, y);
+ else if (allSpecs[piece].moveas)
+ pieceType = allSpecs[piece].moveas;
+ let res = allSpecs[pieceType];
+ if (!res["both"])
+ res.both = [];
+ if (!res["moves"])
+ res.moves = [];
+ if (!res["attack"])
+ res.attack = [];
+ return res;
+ }
+
+ // Can thing on square1 capture thing on square2?
+ canTake([x1, y1], [x2, y2]) {
+ return this.getColor(x1, y1) !== this.getColor(x2, y2);
+ }
+
+ // Teleport & Recycle. Assumption: color(x1,y1) == color(x2,y2)
+ canSelfTake([x1, y1], [x2, y2]) {
+ return !this.isKing(x2, y2);
+ }
+
+ canStepOver(i, j, p) {
+ // In some variants, objects on boards don't stop movement (Chakart)
+ return this.board[i][j] == "";
+ }
+
+ canDrop([c, p], [i, j]) {
+ return (
+ this.board[i][j] == "" &&
+ (!this.enlightened || this.enlightened[i][j]) &&
+ (
+ p != "p" ||
+ (c == 'w' && i < this.size.x - 1) ||
+ (c == 'b' && i > 0)
+ )
+ );
+ }
+
+ // For Madrasi:
+ // (redefined in Baroque etc, where Madrasi condition doesn't make sense)
+ isImmobilized([x, y]) {
+ if (!this.options["madrasi"])
+ return false;
+ const color = this.getColor(x, y);
+ const oppCols = this.getOppCols(color);
+ const piece = this.getPieceType(x, y);
+ const stepSpec = this.getStepSpec(color, x, y, piece);
+ const attacks = stepSpec.both.concat(stepSpec.attack);
+ for (let a of attacks) {
+ outerLoop: for (let step of a.steps) {
+ let [i, j] = this.increment([x, y], step);
+ let stepCounter = 0;
+ while (this.onBoard(i, j) && this.board[i][j] == "") {
+ if (a.range <= stepCounter++)
+ continue outerLoop;
+ [i, j] = this.increment([i, j], step);
+ }
+ if (
+ this.onBoard(i, j) &&
+ oppCols.includes(this.getColor(i, j)) &&
+ this.getPieceType(i, j) == piece
+ ) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }