🚀 benchmark ?

This commit is contained in:
platane
2020-10-06 23:53:46 +02:00
committed by Platane
parent b0784fbaca
commit 16a47349be
10 changed files with 181 additions and 11 deletions

View File

@@ -20,6 +20,8 @@ const createHeuristic = (grid0: Grid) => {
colorCount[color] = (0 | colorCount[color]) + 1;
}
// const colors = Object.keys(colorCount).map((x) => +x);
const target = Object.entries(colorCount)
.sort(([a], [b]) => +a - +b)
.map(([color, length]: any) => Array.from({ length }, () => +color))
@@ -33,9 +35,22 @@ const createHeuristic = (grid0: Grid) => {
_snake: Snake,
stack: Color[]
) => {
const x = target[stack.length];
const colorTarget = target[stack.length];
return (c: Color) => (x === c ? 1 : 0);
// const cc = { ...colorCount };
// for (const color of stack) cc[color]--;
// let colorTarget;
// for (let i = colors.length; i--; )
// if (cc[colors[i]] > 0) colorTarget = colors[i];
return (c: Color) => {
if (colorTarget === c) return 1;
return 0;
// return 1 - Math.abs(colorTarget - c) / 10;
};
};
const isEnd = (_grid: Grid, _snake: Snake, stack: Color[]) =>