Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function allowsEnPassant(piece, movement, targetColumn, targetRow) {
- // this is utter garbage
- // don't look at it
- var lastMove = moveHistory[moveHistory.length - 1];
- if (lastMove != null) {
- var lastPiece = new ChessPiece(lastMove.piece.type.nameID, lastMove.piece.colour, lastMove.origin[0], lastMove.origin[1], true);
- if (enPassantTargets.includes(lastPiece.type.nameID)) {
- if (liesBetween([lastMove.origin[0], lastMove.origin[1]], [targetColumn, targetRow], [lastMove.target[0], lastMove.target[1]], true)) {
- return true;
- }
- }
- }
- return false;
- }
- function liesBetween(pivotA, cell, pivotB, strict) {
- if (strict && (pivotA.equals(cell) || pivotB.equals(cell))) {
- return false;
- }
- return pivotA[0] == cell[0] && pivotB[0] == cell[0] && sameSign(pivotA[1] - cell[1], cell[1] - pivotB[1]) ||
- pivotA[1] == cell[1] && pivotB[1] == cell[1] && sameSign(pivotA[0] - cell[0], cell[0] - pivotB[0]);
- }
- function sameSign(a, b) {
- return a <= 0 && b <= 0 || a >= 0 && b >= 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement