Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created July 16, 2017 22:33
Show Gist options
  • Save JeffML/d3ad2149a8bd895ab50106a52fe33058 to your computer and use it in GitHub Desktop.
Save JeffML/d3ad2149a8bd895ab50106a52fe33058 to your computer and use it in GitHub Desktop.
method used to determine knight moves on a chess board
function knightChecks(boardAndPiece, candidateMoves) {
const newMoves = [];
for (const m of candidateMoves.moves) {
const p = boardAndPiece.board.pieceAt(m)
if (!p) {
newMoves.push(m)
} else if (p.color !== boardAndPiece.piece.color) {
m.hasCaptured = p;
newMoves.push(m)
}
}
return {
moves: newMoves,
moveVectors: [newMoves]
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment