layout: make it deterministic
parent
0c30422c2a
commit
70f7ba9c03
|
@ -725,6 +725,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
|
|||
rowHeight: this.rowHeight,
|
||||
squareMode: this.squareMode,
|
||||
numCols: this.numCols,
|
||||
seed: dayId,
|
||||
});
|
||||
|
||||
// Check if some rows were added
|
||||
|
|
|
@ -13,6 +13,7 @@ export function getLayout(
|
|||
rowHeight: number,
|
||||
squareMode: boolean,
|
||||
numCols: number,
|
||||
seed: number,
|
||||
}
|
||||
): {
|
||||
top: number,
|
||||
|
@ -31,6 +32,9 @@ export function getLayout(
|
|||
}).boxes;
|
||||
}
|
||||
|
||||
// RNG
|
||||
const rand = mulberry32(opts.seed);
|
||||
|
||||
// Binary flags
|
||||
const FLAG_USE = 1 << 0;
|
||||
const FLAG_USED = 1 << 1;
|
||||
|
@ -103,7 +107,7 @@ export function getLayout(
|
|||
(numLeft === 0 || numLeft >= opts.numCols);
|
||||
|
||||
// Full width breakout
|
||||
if (canBreakout && Math.random() < (input.length > 0 ? 0.2 : 0.1)) {
|
||||
if (canBreakout && rand() < (input.length > 0 ? 0.2 : 0.1)) {
|
||||
matrix[row][col] |= FLAG_BREAKOUT;
|
||||
for (let i = 1; i < opts.numCols; i++) {
|
||||
matrix[row][i] |= FLAG_USED;
|
||||
|
@ -111,7 +115,7 @@ export function getLayout(
|
|||
}
|
||||
|
||||
// Use 6 vertically
|
||||
else if (canUse6 && Math.random() < 0.2) {
|
||||
else if (canUse6 && rand() < 0.2) {
|
||||
matrix[row][col] |= FLAG_USE6;
|
||||
matrix[row+1][col] |= FLAG_USED;
|
||||
matrix[row+2][col] |= FLAG_USED;
|
||||
|
@ -121,7 +125,7 @@ export function getLayout(
|
|||
}
|
||||
|
||||
// Use 4 box
|
||||
else if (canUse4 && Math.random() < ((col % 2) ? 0.67 : 0.4)) {
|
||||
else if (canUse4 && rand() < ((col % 2) ? 0.67 : 0.4)) {
|
||||
matrix[row][col] |= FLAG_USE4;
|
||||
matrix[row+1][col] |= FLAG_USED;
|
||||
matrix[row][col+1] |= FLAG_USED;
|
||||
|
@ -199,3 +203,12 @@ function flagMatrixStr(matrix: number[][], numFlag: number) {
|
|||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function mulberry32(a: number) {
|
||||
return function() {
|
||||
var t = a += 0x6D2B79F5;
|
||||
t = Math.imul(t ^ t >>> 15, t | 1);
|
||||
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
||||
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue