🚀 refactor

This commit is contained in:
platane
2020-09-29 11:00:29 +02:00
committed by Platane
parent 8d8956229c
commit 9b92697ef9
5 changed files with 70 additions and 32 deletions

View File

@@ -56,3 +56,28 @@ export const getAvailableRoutes = (
}
}
};
export const getInterestingAvailableRoutes = (
grid: Grid,
snake0: Snake,
onSolution: (snakes: Snake[], color: Color) => boolean,
n = snake0.length
) => {
const solutions: Snake[] = [];
getAvailableRoutes(grid, snake0, (snakes, color) => {
const [snake] = snakes;
for (let j = solutions.length; j--; ) {
let same = true;
for (let i = 0; i < n * 2; i++)
same = same && solutions[j][i] === snake[i];
if (same) return false;
}
solutions.push(snake);
return onSolution(snakes, color);
});
};