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
| var Ba1 = new ChessPiece('Ba1'); | |
| seneca.act({ | |
| role: "movement", | |
| cmd: "rawMoves", | |
| piece: Ba1 | |
| }, (err, msg) => {...}); |
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
| module.exports = function specialMovement(options) { | |
| //... | |
| this.add({ | |
| role: "movement", | |
| cmd: "rawMoves", | |
| isPawn: true | |
| }, (msg, reply) => { | |
| if (msg.piece.piece !== 'P') { | |
| return ("piece was not a pawn") | |
| } |
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
| this.add({ | |
| role: "movement", | |
| cmd: "legalSquares", | |
| }, (msg, reply) => { | |
| const isPawn = msg.piece.piece === 'P'; | |
| const isKnight = msg.piece.piece === 'N'; | |
| this.act({ | |
| role: "movement", | |
| cmd: "rawMoves", |
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
| // m: proposed move | |
| // blockers: blocking pieces | |
| // pp: current piece position | |
| function diagonalChecks(m, blockers, pp) { | |
| let isGood = true; | |
| for (const b of blockers) { | |
| if (b.rank > pp.rank && b.file > pp.file) { | |
| if (m.rank > pp.rank && m.file > pp.file) { | |
| isGood = isGood && (m.rank < b.rank && m.file < b.file); | |
| } |
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
| module.exports = function (boardAndPiece, candidateMoves) { | |
| if (!boardAndPiece.board) return candidateMoves; | |
| const rangeChecks = { | |
| B: vectorChecks, | |
| R: vectorChecks, | |
| K: vectorChecks, | |
| Q: vectorChecks, | |
| P: pawnChecks, | |
| N: knightChecks |
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) |
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
| const legalMovesWithBoard = require("./helpers/legalMovesWithBoard") | |
| //... | |
| this.add('role:movement,cmd:legalMoves', function (msg, reply) { | |
| this.prior(msg, function (err, result) { | |
| if (msg.board) { | |
| const result2 = legalMovesWithBoard(msg, result); | |
| //... |
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
| this.add('role:movement,cmd:legalMoves', function (msg, reply) { | |
| this.prior(msg, function (err, result) { | |
| if (msg.board) { | |
| const result2 = legalMovesWithBoard(msg, result); | |
| if (msg.piece.piece === 'K') { | |
| legalMovesWithKing.call(this, msg, result2, reply) | |
| } else { | |
| reply(err, result2); | |
| } | |
| } else { |
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
| module.exports = function (boardAndPiece, candidateMoves, reply) { | |
| const opposingColor = boardAndPiece.piece.color === 'W' ? 'black' : 'white'; | |
| //temporarily remove the K to avoid cycles | |
| boardAndPiece.board.removePiece(boardAndPiece.piece); | |
| function canCastle(king, rook, intervening, opposing) { | |
| // console.log("canCastle", arguments) | |
| const opposingControlled = [...opposing.controlled] |
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
| module.exports = function squareControl() { | |
| const getSquaresControlledBy = (board, pieceColor) => { | |
| var pieces = board.boardPieces[pieceColor]; | |
| const promises = pieces.map(p => | |
| new Promise(resolve => { | |
| this.act({ | |
| role: "movement", | |
| cmd: "legalMoves", | |
| piece: p, |