Skip to content

Instantly share code, notes, and snippets.

@kinostl
Created March 13, 2021 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinostl/412c547f55e556c77b98b7255ecfa83d to your computer and use it in GitHub Desktop.
Save kinostl/412c547f55e556c77b98b7255ecfa83d to your computer and use it in GitHub Desktop.
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