+/**
+ * If this is a Chess960 castling which doesn't move the king,
+ * move the rook instead.
+*/
+var patch_move = function(move) {
+ if (move === null) return null;
+ if (move.from !== move.to) return move;
+
+ var f = move.rook_sq & 15;
+ var r = move.rook_sq >> 4;
+ var from = ('abcdefgh'.substring(f,f+1) + '87654321'.substring(r,r+1));
+ var to = move.to;
+
+ if (move.to === 'g1') {
+ to = 'f1';
+ } else if (move.to === 'g8') {
+ to = 'f8';
+ } else if (move.to === 'b1') {
+ to = 'c1';
+ } else if (move.to === 'b8') {
+ to = 'c8';
+ }
+
+ return { from: from, to: to };
+}
+