- for (let i=0; i<8; i++) {
- for (let j=0; j<8; j++) {
- if (this.getColor(i, j) == color) {
- switch (this.getPiece(i, j)) {
- case V.PAWN: {
- // Pushed pawns move as enemy pawns
- const shift = (color == 'w' ? 1 : -1);
- if (x + shift == i && Math.abs(y - j) == 1)
- moves.push(this.getBasicMove([i, j], [x, y]));
- break;
- }
- case V.KNIGHT: {
- const deltaX = Math.abs(i - x);
- const deltaY = Math.abs(j - y);
- if (
- deltaX + deltaY == 3 &&
- [1, 2].includes(deltaX) &&
- [1, 2].includes(deltaY)
- ) {
- moves.push(this.getBasicMove([i, j], [x, y]));
- }
- break;
- }
- case V.KING:
- if (Math.abs(i - x) <= 1 && Math.abs(j - y) <= 1)
- moves.push(this.getBasicMove([i, j], [x, y]));
- break;
- case V.ROOK: {
- const mv = sliderAttack(i, j, V.steps[V.ROOK]);
- if (!!mv) moves.push(mv);
- break;
- }
- case V.BISHOP: {
- const mv = sliderAttack(i, j, V.steps[V.BISHOP]);
- if (!!mv) moves.push(mv);
- break;
- }
- case V.QUEEN: {
- const mv = sliderAttack(
- i, j, V.steps[V.ROOK].concat(V.steps[V.BISHOP]));
- if (!!mv) moves.push(mv);
- break;
- }
+ if (!!from) {
+ const theMove = getTargetedCaptures(from);
+ if (!!theMove) moves.push(theMove);
+ }
+ else {
+ for (let i=0; i<8; i++) {
+ for (let j=0; j<8; j++) {
+ if (this.getColor(i, j) == color) {
+ const newMove = getTargetedCaptures([i, j]);
+ if (!!newMove) moves.push(newMove);