util = {
const toDests = (chess) => {
const dests = new Map();
chess.SQUARES.forEach(s => {
const ms = chess.moves({square: s, verbose: true});
if (ms.length) dests.set(s, ms.map(m => m.to));
});
return dests;
}
const toColor = (chess) => {
return (chess.turn() === 'w') ? 'white' : 'black';
}
const playOtherSide = (cg, chess) => {
return (orig, dest) => {
chess.move({from: orig, to: dest});
cg.set({
check:chess.in_check(),
movable: {
color: toColor(chess),
dests: toDests(chess)
}
});
};
}
return {toDests, toColor, playOtherSide}
}