Conflict
This commit is contained in:
@@ -215,56 +215,4 @@ while (openList.length > 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printMap();
|
printMap();
|
||||||
<<<<<<< Updated upstream
|
|
||||||
|
|
||||||
let fastest: number|null = null;
|
|
||||||
|
|
||||||
const scoreCache: { [key: string]: [number, Coord, Dir] } = {};
|
|
||||||
|
|
||||||
const branchCache: { [key: string]: number } = {};
|
|
||||||
|
|
||||||
const scores: Array<Array<Coord>> = [];
|
|
||||||
|
|
||||||
function getScoresAfterPosition(pos: Coord, dir: Dir, path: Array<Coord> = [], lastBranch: [number, Coord]|null = null): void {
|
|
||||||
if (fastest !== null && path.length >= fastest) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const branch = isBranch(pos, dir);
|
|
||||||
if (branch) {
|
|
||||||
const cacheKey = `${pos.x},${pos.y},${dir}`;
|
|
||||||
const cache = branchCache[cacheKey];
|
|
||||||
if (cache && cache < path.length) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
branchCache[cacheKey] = path.length;
|
|
||||||
}
|
|
||||||
lastBranch = [path.length, pos];
|
|
||||||
}
|
|
||||||
[dir, nextDir(dir), prevDir(dir)].forEach((newDir, i) => {
|
|
||||||
const next = nextCoord(pos, newDir);
|
|
||||||
if (!path.find(({ x, y }) => next.x === x && next.y === y)) {
|
|
||||||
if (next.x === width - 1 && next.y === height - 1) {
|
|
||||||
if (fastest === null || path.length < fastest) {
|
|
||||||
fastest = path.length;
|
|
||||||
}
|
|
||||||
scores.push(path);
|
|
||||||
return;
|
|
||||||
} else if (next.x >= 0 && next. x < width && next.y >= 0 && next.y < height && get(next) === '.') {
|
|
||||||
getScoresAfterPosition(next, newDir, [...path, next], lastBranch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
getScoresAfterPosition({ x: 0, y: 0 }, Dir.Up, [{ x: 0, y: 0 }]);
|
|
||||||
|
|
||||||
console.log(scores);
|
|
||||||
const fastestScore = Math.min(...scores.map((p) => p.length));
|
|
||||||
const fastestPath = scores.find((p) => p.length === fastestScore);
|
|
||||||
printMap(fastestPath);
|
|
||||||
console.log(fastestScore);
|
|
||||||
=======
|
|
||||||
console.log(path, path.length)
|
console.log(path, path.length)
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|||||||
Reference in New Issue
Block a user