- let res = [];
- square.split(",").forEach(sq => {
- res.push(V.SquareToCoords(sq));
- });
- return res;
+ // Expand init + dest squares into a full path:
+ const init = V.SquareToCoords(square.substr(0, 2));
+ let newPath = [init];
+ if (square.length == 2) return newPath;
+ const dest = V.SquareToCoords(square.substr(2));
+ const delta = ['x', 'y'].map(i => Math.abs(dest[i] - init[i]));
+ // Check if it's a knight(rider) movement:
+ let step = [0, 0];
+ if (delta[0] > 0 && delta[1] > 0 && delta[0] != delta[1]) {
+ // Knightrider
+ const minShift = Math.min(delta[0], delta[1]);
+ step[0] = (dest.x - init.x) / minShift;
+ step[1] = (dest.y - init.y) / minShift;
+ } else {
+ // "Sliders"
+ step = ['x', 'y'].map((i, idx) => {
+ return (dest[i] - init[i]) / delta[idx] || 0
+ });
+ }
+ let x = init.x + step[0],
+ y = init.y + step[1];
+ while (x != dest.x || y != dest.y) {
+ newPath.push({ x: x, y: y });
+ x += step[0];
+ y += step[1];
+ }
+ newPath.push(dest);
+ return newPath;