Created
March 13, 2021 18:41
-
-
Save kinostl/412c547f55e556c77b98b7255ecfa83d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg from 'lodash' | |
const {sampleSize, random} = pkg | |
let startPoints=['Start','TheKitchen','TheBallPit','TheSandbox','TheClubhouse','TheWall','WutheringHeights','TheQuizKing','TheJazzClub','TheMudpit'] | |
let endPoints = startPoints.concat(['TheEnd', 'HotSpot', 'HotPot', 'Osen', 'KeyMan']) | |
let nodes= new Set() | |
let map=new Set() | |
let endReachable=false | |
let keyReachable=false | |
let everythingEnterable=false | |
let firstRun=true | |
while(!endReachable || !keyReachable || !everythingEnterable){ | |
for(let startPoint of startPoints){ | |
let connections=random(1,2) | |
let samples=sampleSize(endPoints, connections) | |
if(startPoint=="Start"){ | |
samples=sampleSize(startPoints, connections) | |
} | |
if(samples.includes('TheEnd')) endReachable=true | |
if(samples.includes('KeyMan')) keyReachable=true | |
for(let sample of samples){ | |
if(sample == startPoint) continue | |
nodes.add(sample) | |
map.add(`${startPoint} --> ${sample}`) | |
} | |
if(endReachable && keyReachable && everythingEnterable && !firstRun) break; | |
} | |
if(firstRun=true) firstRun=false | |
let nodeArr = Array.from(nodes) | |
everythingEnterable = startPoints.every(i=>nodeArr.includes(i)) | |
} | |
let mapArr = Array.from(map) | |
console.log(mapArr.join('\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment