First commit, done on M6 from the PLAN.MD

This commit is contained in:
gauvainboiche
2026-10-25 17:34:44 +01:00
parent d5dc2a3901
commit 04193e2013
86 changed files with 8396 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// mulberry32 PRNG. The generator state lives in state.rngState (a uint32) so a
// saved game resumes with the exact same sequence.
export function nextFloat(state) {
state.rngState = (state.rngState + 0x6d2b79f5) >>> 0;
let t = state.rngState;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
// Uniform in [-amp, amp].
export function nextNoise(state, amp) {
return (nextFloat(state) * 2 - 1) * amp;
}
export function nextInt(state, maxExclusive) {
return Math.floor(nextFloat(state) * maxExclusive);
}
export function pickWeighted(state, items, weights) {
let total = 0;
for (const w of weights) total += w;
if (total <= 0) return null;
let r = nextFloat(state) * total;
for (let i = 0; i < items.length; i++) {
r -= weights[i];
if (r < 0) return items[i];
}
return items[items.length - 1];
}