Tuned Shortest Path contract generation

Now generates about 4/5 puzzles where a path exists and 1/5 with the destination
completely blocked off.
This commit is contained in:
Heikki Aitakangas 2022-04-02 04:27:38 +03:00
parent fb0cc15794
commit 809f8f6687

@ -838,9 +838,10 @@ export const codingContractTypesMetadata: ICodingContractTypeMetadata[] = [
if(y == 0 && x == 0) continue; // Don't block start
if(y == dstY && x == dstX) continue; // Don't block destination
// Generate more obstacles the farther a position is from start and destination,
// with minimum obstacle chance of 15%
const distanceFactor = Math.min(y + x, dstY - y + dstX - x) / minPathLength;
// Generate more obstacles the farther a position is from start and destination.
// Raw distance factor peaks at 50% at half-way mark. Rescale to 40% max.
// Obstacle chance range of [15%, 40%] produces ~78% solvable puzzles
const distanceFactor = Math.min(y + x, dstY - y + dstX - x) / minPathLength * 0.8;
if (Math.random() < Math.max(0.15, distanceFactor))
grid[y][x] = 1;
}