Skip to content

Commit

Permalink
Reenables another pin test.
Browse files Browse the repository at this point in the history
  • Loading branch information
aryann committed Nov 11, 2024
1 parent a6606f2 commit ba869b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
12 changes: 11 additions & 1 deletion engine/src/moves.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ describe("castling", () => {
]);
});

it.skip("pinned pieces", () => {
it("pinned pieces", () => {
const generator = make("K7/8/8/8/8/5Q2/8/7q");

assert.sameDeepMembers(generator.generateMoves("f3"), [
Expand All @@ -1095,6 +1095,16 @@ describe("castling", () => {
to: "b7",
type: "normal",
},
{
from: "f3",
to: "g2",
type: "normal",
},
{
from: "f3",
to: "h1",
type: "normal",
},
]);
});
});
25 changes: 12 additions & 13 deletions engine/src/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
UP_LEFT,
UP_RIGHT,
} from "./offsets";
import { pins, TAllowedMoves } from "./pins";
import {
getRank,
getSide,
Expand Down Expand Up @@ -53,23 +54,21 @@ export class MoveGenerator {
}

// TODO(aryann): Remove this check once all test boards have kings on them.
// const side = getSide(piece);
// let pinnedPieces: Map<TSquare, TAllowedMoves> = new Map();
// try {
// const kingSquare = this.board.getKingSquare(side);
// pinnedPieces = pins(this.board, kingSquare);
// } catch (e) {}
const side = getSide(piece);
let pinnedPieces: Map<TSquare, TAllowedMoves> = new Map();
try {
const kingSquare = this.board.getKingSquare(side);
pinnedPieces = pins(this.board, kingSquare);
} catch (e) {}

const moves: TMove[] = [];

for (const move of this.generatePseudoLegalMoves(from)) {
// TODO(aryann): Enable this once the pinning logic works:
//
// const pinnedPiece = pinnedPieces.get(move.from);
// if (pinnedPiece && !pinnedPiece.includes(move.to)) {
// // Pinned pieces cannot be moved.
// continue;
// }
const pinnedPiece = pinnedPieces.get(move.from);
if (pinnedPiece && !pinnedPiece.includes(move.to)) {
// Pinned pieces cannot be moved.
continue;
}

// TODO(aryann): If the king is currently in check, exclude all moves that
// do not take the king out of check.
Expand Down

0 comments on commit ba869b4

Please sign in to comment.