Add dockerfile and more variety for formulas
This commit is contained in:
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
|
||||||
|
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN git clone https://git.raphaelforment.fr/BuboBubo/bruitiste .
|
||||||
|
|
||||||
|
RUN pnpm install --frozen-lockfile
|
||||||
|
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
@ -10,13 +10,15 @@ const SHIFTS = [...SHIFT_LOW, ...SHIFT_MID, ...SHIFT_HIGH]
|
|||||||
|
|
||||||
const MASKS = [1, 2, 3, 4, 5, 7, 8, 11, 13, 15, 16, 31, 32, 42, 63, 64, 127, 128, 255]
|
const MASKS = [1, 2, 3, 4, 5, 7, 8, 11, 13, 15, 16, 31, 32, 42, 63, 64, 127, 128, 255]
|
||||||
const MULTIPLIERS = [2, 3, 5, 7, 11, 13]
|
const MULTIPLIERS = [2, 3, 5, 7, 11, 13]
|
||||||
|
const MELODIC_MODS = [3, 5, 7, 9, 12, 16, 24, 32, 48, 64, 96, 128, 192, 255]
|
||||||
|
const DIV_FACTORS = [2, 3, 4, 5, 6, 8, 10, 12, 16, 24, 32]
|
||||||
const SMALL_NUMS = [1, 2, 3, 4, 5, 6, 7, 8]
|
const SMALL_NUMS = [1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
|
|
||||||
const TEMPLATES: Template[] = [
|
const TEMPLATES: Template[] = [
|
||||||
{ pattern: "t*(N&t>>S)", weight: 8 },
|
{ pattern: "t*(N&t>>S)", weight: 8 },
|
||||||
{ pattern: "t*((t>>S)&N)", weight: 8 },
|
{ pattern: "t*((t>>S)&N)", weight: 8 },
|
||||||
{ pattern: "t*(N|(t>>S))", weight: 5 },
|
{ pattern: "t*(N|(t>>S))", weight: 5 },
|
||||||
{ pattern: "(t*M&t>>S1)|(t*M2&t>>S2)", weight: 10 },
|
{ pattern: "(t*X&t>>S1)|(t*X2&t>>S2)", weight: 10 },
|
||||||
{ pattern: "t*(t>>S1|t>>S2)", weight: 10 },
|
{ pattern: "t*(t>>S1|t>>S2)", weight: 10 },
|
||||||
{ pattern: "t*(t>>S1&t>>S2)", weight: 8 },
|
{ pattern: "t*(t>>S1&t>>S2)", weight: 8 },
|
||||||
{ pattern: "(t>>S1)|(t>>S2)", weight: 7 },
|
{ pattern: "(t>>S1)|(t>>S2)", weight: 7 },
|
||||||
@ -25,7 +27,7 @@ const TEMPLATES: Template[] = [
|
|||||||
{ pattern: "(t&t>>S1)*(t>>S2|t>>S3)", weight: 8 },
|
{ pattern: "(t&t>>S1)*(t>>S2|t>>S3)", weight: 8 },
|
||||||
{ pattern: "(t>>S)&N", weight: 5 },
|
{ pattern: "(t>>S)&N", weight: 5 },
|
||||||
{ pattern: "t*(t>>S)", weight: 4 },
|
{ pattern: "t*(t>>S)", weight: 4 },
|
||||||
{ pattern: "(t*M)&(t>>S)", weight: 6 },
|
{ pattern: "(t*X)&(t>>S)", weight: 6 },
|
||||||
{ pattern: "t^(t>>S)", weight: 5 },
|
{ pattern: "t^(t>>S)", weight: 5 },
|
||||||
{ pattern: "(t>>S1)^(t>>S2)", weight: 6 },
|
{ pattern: "(t>>S1)^(t>>S2)", weight: 6 },
|
||||||
{ pattern: "t*(N&(t>>S1|t>>S2))", weight: 7 },
|
{ pattern: "t*(N&(t>>S1|t>>S2))", weight: 7 },
|
||||||
@ -36,8 +38,38 @@ const TEMPLATES: Template[] = [
|
|||||||
{ pattern: "t<<((t>>S1|t>>S2)^(t>>S3))", weight: 4 },
|
{ pattern: "t<<((t>>S1|t>>S2)^(t>>S3))", weight: 4 },
|
||||||
{ pattern: "(t>>S)%(N)", weight: 3 },
|
{ pattern: "(t>>S)%(N)", weight: 3 },
|
||||||
{ pattern: "t%(N)+(t>>S)", weight: 4 },
|
{ pattern: "t%(N)+(t>>S)", weight: 4 },
|
||||||
{ pattern: "(t*M&t>>S1)^(t>>S2)", weight: 5 },
|
{ pattern: "(t*X&t>>S1)^(t>>S2)", weight: 5 },
|
||||||
{ pattern: "((t>>S1)|(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 }
|
{ pattern: "((t>>S1)|(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 },
|
||||||
|
|
||||||
|
{ pattern: "t&t>>S", weight: 7 },
|
||||||
|
{ pattern: "(t>>S1&t>>S2)*t>>S3", weight: 6 },
|
||||||
|
{ pattern: "(t&(t>>S1))&(t>>S2)", weight: 6 },
|
||||||
|
{ pattern: "((t>>S1)&t)*(t>>S2&t)", weight: 7 },
|
||||||
|
{ pattern: "t&(t>>S1)&(t>>S2)", weight: 6 },
|
||||||
|
|
||||||
|
{ pattern: "t%(M1)+(t>>S1)%(M2)", weight: 7 },
|
||||||
|
{ pattern: "(t%M)*(t>>S)", weight: 6 },
|
||||||
|
{ pattern: "t*((t>>S1)%(M))", weight: 6 },
|
||||||
|
{ pattern: "(t*(t>>S))%M", weight: 5 },
|
||||||
|
{ pattern: "(t%M1)^(t>>S)%(M2)", weight: 5 },
|
||||||
|
{ pattern: "((t>>S)%M1)*(t%M2)", weight: 6 },
|
||||||
|
|
||||||
|
{ pattern: "t/(t%(t>>S))", weight: 4 },
|
||||||
|
{ pattern: "t/(D+(t>>S))", weight: 5 },
|
||||||
|
{ pattern: "t/(D+(t>>S1|t>>S2))", weight: 5 },
|
||||||
|
{ pattern: "(t>>S)/(D+(t&N))", weight: 4 },
|
||||||
|
{ pattern: "t/(D*(t>>S))", weight: 4 },
|
||||||
|
|
||||||
|
{ pattern: "t^(t>>S1)^(t>>S2)", weight: 6 },
|
||||||
|
{ pattern: "((t>>S1)^(t>>S2))*(t>>S3)", weight: 7 },
|
||||||
|
{ pattern: "(t^t>>S1)&(t^t>>S2)", weight: 6 },
|
||||||
|
{ pattern: "t^(t>>S1)^(t>>S2)^(t>>S3)", weight: 5 },
|
||||||
|
{ pattern: "(t^(t>>S1))*(t^(t>>S2))", weight: 6 },
|
||||||
|
|
||||||
|
{ pattern: "((t*t)/(t^t>>S))&N", weight: 5 },
|
||||||
|
{ pattern: "(t*(t>>S1))^(t*(t>>S2))", weight: 6 },
|
||||||
|
{ pattern: "((t>>S1)*(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 },
|
||||||
|
{ pattern: "(t&(t>>S1))^((t>>S2)&(t>>S3))", weight: 5 }
|
||||||
]
|
]
|
||||||
|
|
||||||
function randomElement<T>(arr: T[]): T {
|
function randomElement<T>(arr: T[]): T {
|
||||||
@ -62,7 +94,21 @@ function fillTemplate(pattern: string): string {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const mMatches = formula.match(/M\d*/g) || []
|
const mMatches = formula.match(/M\d*/g) || []
|
||||||
const uniqueMults = [...new Set(mMatches)]
|
const uniqueMods = [...new Set(mMatches)]
|
||||||
|
uniqueMods.forEach(placeholder => {
|
||||||
|
const mod = randomElement(MELODIC_MODS)
|
||||||
|
formula = formula.replace(new RegExp(placeholder, 'g'), mod.toString())
|
||||||
|
})
|
||||||
|
|
||||||
|
const dMatches = formula.match(/D\d*/g) || []
|
||||||
|
const uniqueDivs = [...new Set(dMatches)]
|
||||||
|
uniqueDivs.forEach(placeholder => {
|
||||||
|
const div = randomElement(DIV_FACTORS)
|
||||||
|
formula = formula.replace(new RegExp(placeholder, 'g'), div.toString())
|
||||||
|
})
|
||||||
|
|
||||||
|
const xMatches = formula.match(/X\d*/g) || []
|
||||||
|
const uniqueMults = [...new Set(xMatches)]
|
||||||
uniqueMults.forEach(placeholder => {
|
uniqueMults.forEach(placeholder => {
|
||||||
const mult = randomElement(MULTIPLIERS)
|
const mult = randomElement(MULTIPLIERS)
|
||||||
formula = formula.replace(new RegExp(placeholder, 'g'), mult.toString())
|
formula = formula.replace(new RegExp(placeholder, 'g'), mult.toString())
|
||||||
@ -71,6 +117,44 @@ function fillTemplate(pattern: string): string {
|
|||||||
return formula
|
return formula
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyParenthesizationRandomization(formula: string): string {
|
||||||
|
if (Math.random() < 0.2) {
|
||||||
|
const operators = formula.match(/[\+\-\*\/\&\|\^]/g)
|
||||||
|
if (operators && operators.length > 0) {
|
||||||
|
const parts = formula.split(/([+\-*\/&|^])/)
|
||||||
|
if (parts.length >= 3) {
|
||||||
|
const idx = Math.floor(Math.random() * (parts.length - 2) / 2) * 2
|
||||||
|
parts[idx] = `(${parts[idx]})`
|
||||||
|
}
|
||||||
|
return parts.join('')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return formula
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyNegationRandomization(formula: string): string {
|
||||||
|
const tMatches = [...formula.matchAll(/\bt\b/g)]
|
||||||
|
if (tMatches.length === 0) return formula
|
||||||
|
|
||||||
|
if (Math.random() < 0.1) {
|
||||||
|
const idx = Math.floor(Math.random() * tMatches.length)
|
||||||
|
const match = tMatches[idx]
|
||||||
|
const before = formula.slice(0, match.index!)
|
||||||
|
const after = formula.slice(match.index! + 1)
|
||||||
|
return before + '(-t)' + after
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.random() < 0.15) {
|
||||||
|
const idx = Math.floor(Math.random() * tMatches.length)
|
||||||
|
const match = tMatches[idx]
|
||||||
|
const before = formula.slice(0, match.index!)
|
||||||
|
const after = formula.slice(match.index! + 1)
|
||||||
|
return before + '(~t)' + after
|
||||||
|
}
|
||||||
|
|
||||||
|
return formula
|
||||||
|
}
|
||||||
|
|
||||||
export function generateRandomFormula(complexity: number = 1): string {
|
export function generateRandomFormula(complexity: number = 1): string {
|
||||||
const complexityWeights = [
|
const complexityWeights = [
|
||||||
{ simple: 0.6, medium: 0.3, complex: 0.1 },
|
{ simple: 0.6, medium: 0.3, complex: 0.1 },
|
||||||
@ -81,7 +165,7 @@ export function generateRandomFormula(complexity: number = 1): string {
|
|||||||
const weights = complexityWeights[complexity] || complexityWeights[1]
|
const weights = complexityWeights[complexity] || complexityWeights[1]
|
||||||
|
|
||||||
const filteredTemplates = TEMPLATES.map(t => {
|
const filteredTemplates = TEMPLATES.map(t => {
|
||||||
const patternComplexity = (t.pattern.match(/[S|N|M]\d*/g) || []).length
|
const patternComplexity = (t.pattern.match(/[SNMDX]\d*/g) || []).length
|
||||||
let weight = t.weight
|
let weight = t.weight
|
||||||
|
|
||||||
if (patternComplexity <= 2) {
|
if (patternComplexity <= 2) {
|
||||||
@ -109,9 +193,12 @@ export function generateRandomFormula(complexity: number = 1): string {
|
|||||||
|
|
||||||
let formula = fillTemplate(selectedTemplate.pattern)
|
let formula = fillTemplate(selectedTemplate.pattern)
|
||||||
|
|
||||||
const extraLayerChance = complexity === 0 ? 0.05 : complexity === 1 ? 0.15 : 0.25
|
formula = applyParenthesizationRandomization(formula)
|
||||||
|
formula = applyNegationRandomization(formula)
|
||||||
|
|
||||||
|
const extraLayerChance = complexity === 0 ? 0.10 : complexity === 1 ? 0.20 : 0.35
|
||||||
if (Math.random() < extraLayerChance) {
|
if (Math.random() < extraLayerChance) {
|
||||||
const op = randomElement(['&', '|', '^'])
|
const op = randomElement(['&', '|', '^', '+', '-', '*'])
|
||||||
const num = randomElement(SMALL_NUMS)
|
const num = randomElement(SMALL_NUMS)
|
||||||
formula = `(${formula})${op}${num}`
|
formula = `(${formula})${op}${num}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user