Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created May 29, 2017 21:59
Show Gist options
  • Save JeffML/646c85f6242bb27054d841bfaa466aee to your computer and use it in GitHub Desktop.
Save JeffML/646c85f6242bb27054d841bfaa466aee to your computer and use it in GitHub Desktop.
this.add({
role: "movement",
cmd: "rawMoves",
}, (msg, reply) => {
var err = null;
var rawMoves = [];
var pos = msg.piece.position;
switch (msg.piece.piece) {
case 'R':
rawMoves = rankAndFile(pos);
break;
case 'B':
rawMoves = diagonal(pos);
break;
case 'Q':
rawMoves = rankAndFile(pos)
.concat(diagonal(pos));
break;
case 'K':
rawMoves = rankAndFile(pos, 1)
.concat(diagonal(pos, 1))
break;
default:
err = "unhandled " + msg.piece;
break;
};
reply(err, rawMoves);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment