Created
July 16, 2017 22:33
-
-
Save JeffML/d3ad2149a8bd895ab50106a52fe33058 to your computer and use it in GitHub Desktop.
method used to determine knight moves on a chess board
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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