on master help sign in
bridge/src/lib/child.js
20 lines 659 B history raw
1const MIN_GALAXY = 0;
2const MIN_STAR = Math.pow(2, 8);
3const MIN_PLANET = Math.pow(2, 16);
4const MAX_GALAXY = MIN_STAR - 1;
5const MAX_STAR = MIN_PLANET - 1;
7const randomStarName = galaxy =>
8 // ( random in range 0x1 .. 0xff ) * 0x100 + 0x??
9 (Math.floor(Math.random() * MAX_GALAXY) + 1) * MIN_STAR + galaxy;
11const randomPlanetName = star =>
12 // ( random in range 0x1 .. 0xffff ) * 0x10000 + 0x????
13 (Math.floor(Math.random() * MAX_STAR) + 1) * MIN_PLANET + star;
15const getSpawnCandidate = point =>
16 point >= MIN_GALAXY && point < MIN_STAR
17 ? randomStarName(point)
18 : randomPlanetName(point);
20export { getSpawnCandidate };