diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f6459b2e --- /dev/null +++ b/Dockerfile @@ -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;"] diff --git a/src/utils/bytebeatFormulas.ts b/src/utils/bytebeatFormulas.ts index 43d86a86..b200c9f0 100644 --- a/src/utils/bytebeatFormulas.ts +++ b/src/utils/bytebeatFormulas.ts @@ -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 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 TEMPLATES: Template[] = [ { pattern: "t*(N&t>>S)", weight: 8 }, { pattern: "t*((t>>S)&N)", weight: 8 }, { 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: 8 }, { 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>>S)&N", weight: 5 }, { 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>>S1)^(t>>S2)", weight: 6 }, { 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>>S)%(N)", weight: 3 }, { pattern: "t%(N)+(t>>S)", weight: 4 }, - { pattern: "(t*M&t>>S1)^(t>>S2)", weight: 5 }, - { pattern: "((t>>S1)|(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 } + { pattern: "(t*X&t>>S1)^(t>>S2)", weight: 5 }, + { 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(arr: T[]): T { @@ -62,7 +94,21 @@ function fillTemplate(pattern: string): string { }) 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 => { const mult = randomElement(MULTIPLIERS) formula = formula.replace(new RegExp(placeholder, 'g'), mult.toString()) @@ -71,6 +117,44 @@ function fillTemplate(pattern: string): string { 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 { const complexityWeights = [ { 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 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 if (patternComplexity <= 2) { @@ -109,9 +193,12 @@ export function generateRandomFormula(complexity: number = 1): string { 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) { - const op = randomElement(['&', '|', '^']) + const op = randomElement(['&', '|', '^', '+', '-', '*']) const num = randomElement(SMALL_NUMS) formula = `(${formula})${op}${num}` }