From 809f8f6687b81668f49f2b99dce784cea1ea4ec6 Mon Sep 17 00:00:00 2001 From: Heikki Aitakangas Date: Sat, 2 Apr 2022 04:27:38 +0300 Subject: [PATCH] Tuned Shortest Path contract generation Now generates about 4/5 puzzles where a path exists and 1/5 with the destination completely blocked off. --- src/data/codingcontracttypes.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/data/codingcontracttypes.ts b/src/data/codingcontracttypes.ts index a3ee24632..2c88b87a6 100644 --- a/src/data/codingcontracttypes.ts +++ b/src/data/codingcontracttypes.ts @@ -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; }