1 class LoserRules
extends ChessRules
5 const epSq
= this.moves
.length
> 0 ? this.getEpSquare(this.lastMove
) : undefined;
6 this.epSquares
= [ epSq
];
11 // No castling, hence no flags; but flags defined for compatibility
12 this.castleFlags
= "0000";
15 getPotentialPawnMoves([x
,y
])
17 let moves
= super.getPotentialPawnMoves([x
,y
]);
19 // Complete with promotion(s) into king, if possible
20 const color
= this.turn
;
21 const V
= VariantRules
;
22 const [sizeX
,sizeY
] = VariantRules
.size
;
23 const shift
= (color
== "w" ? -1 : 1);
24 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
25 if (x
+shift
== lastRank
)
29 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
30 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:p
}));
32 if (y
>0 && this.canTake([x
,y
], [x
+shift
,y
-1]) && this.board
[x
+shift
][y
-1] != V
.EMPTY
)
33 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:p
}));
34 if (y
<sizeY
-1 && this.canTake([x
,y
], [x
+shift
,y
+1]) && this.board
[x
+shift
][y
+1] != V
.EMPTY
)
35 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:p
}));
41 getPotentialKingMoves(sq
)
43 const V
= VariantRules
;
44 return this.getSlideNJumpMoves(sq
,
45 V
.steps
[V
.ROOK
].concat(V
.steps
[V
.BISHOP
]), "oneStep");
48 // Stop at the first capture found (if any)
51 const color
= this.turn
;
52 const oppCol
= this.getOppCol(color
);
53 const [sizeX
,sizeY
] = VariantRules
.size
;
54 for (let i
=0; i
<sizeX
; i
++)
56 for (let j
=0; j
<sizeY
; j
++)
58 if (this.board
[i
][j
] != VariantRules
.EMPTY
&& this.getColor(i
,j
) != oppCol
)
60 const moves
= this.getPotentialMovesFrom([i
,j
]);
63 for (let k
=0; k
<moves
.length
; k
++)
65 if (moves
[k
].vanish
.length
==2 && this.filterValid([moves
[k
]]).length
> 0)
75 // Trim all non-capturing moves
76 static KeepCaptures(moves
)
78 return moves
.filter(m
=> { return m
.vanish
.length
== 2; });
81 getPossibleMovesFrom(sq
)
83 let moves
= this.filterValid( this.getPotentialMovesFrom(sq
) );
84 // This is called from interface: we need to know if a capture is possible
85 if (this.atLeastOneCapture())
86 moves
= VariantRules
.KeepCaptures(moves
);
92 let moves
= super.getAllValidMoves();
93 if (moves
.some(m
=> { return m
.vanish
.length
== 2; }))
94 moves
= VariantRules
.KeepCaptures(moves
);
100 return false; //No notion of check
103 getCheckSquares(move)
109 updateVariables(move) { }
110 unupdateVariables(move) { }
111 parseFlags(flags
) { }
115 // No valid move: you win!
116 return this.turn
== "w" ? "1-0" : "0-1";
119 static get VALUES() { //experimental...
130 static get SEARCH_DEPTH() { return 4; }
134 return - super.evalPosition(); //better with less material