From 185d48bc5097e38ad1dd97c124e9deff6ac8c9d4 Mon Sep 17 00:00:00 2001 From: karthik Date: Sun, 3 Aug 2025 13:12:16 +0530 Subject: [PATCH] fix : 1st 6 is working properly for every section --- .../selection.service/selection.service.ts | 118 +++++++++--------- 1 file changed, 62 insertions(+), 56 deletions(-) diff --git a/btc-UI/src/app/components/selection.service/selection.service.ts b/btc-UI/src/app/components/selection.service/selection.service.ts index e67229b..0978dd7 100644 --- a/btc-UI/src/app/components/selection.service/selection.service.ts +++ b/btc-UI/src/app/components/selection.service/selection.service.ts @@ -41,11 +41,7 @@ export class SelectionService { const numbers = updated.numbers || []; const isBoxed = updated.isBoxed ?? false; - // Enforce ticket number limit (1-100) - if (value > 100) { - updated.value = 100; - } - + if (value > 100) updated.value = 100; updated.total = 0; if ((numbers.length > 0 || numbers.includes('F')) && value > 0 && label) { @@ -56,34 +52,37 @@ export class SelectionService { case 'PLC': case 'SHW': case 'WSP': { - if (numbers.includes('F')) { - updated.total = this.runnerCount * value * 10; - } else { - updated.total = numbers.filter(n => typeof n === 'number').length * value * 10; - } + updated.total = numbers.includes('F') + ? this.runnerCount * value * 10 + : numbers.filter(n => typeof n === 'number').length * value * 10; break; } - case 'FOR': - case 'EXA': { + case 'FOR': { const dashIndex = numbers.indexOf('-'); const group1 = dashIndex === -1 ? numbers : numbers.slice(0, dashIndex); const group2 = dashIndex === -1 ? [] : numbers.slice(dashIndex + 1); - const group1Count = group1.includes('F') ? this.runnerCount : group1.filter(n => typeof n === 'number').length; - const group2Count = group2.includes('F') ? this.runnerCount : group2.filter(n => typeof n === 'number').length; let combinations = 0; - if (isBoxed) { - const allNums = [...group1, ...group2].filter(n => typeof n === 'number') as number[]; - const uniqueCount = group1.includes('F') || group2.includes('F') ? this.runnerCount : new Set(allNums).size; - combinations = uniqueCount >= 2 ? this.calculatePermutations(uniqueCount) : 0; - updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])]; + if (!isBoxed && !group1.includes('F') && !group2.includes('F')) { + const numGroup1 = group1.filter(n => typeof n === 'number') as number[]; + const numGroup2 = group2.filter(n => typeof n === 'number') as number[]; + for (const a of numGroup1) { + for (const b of numGroup2) { + if (a !== b) combinations++; + } + } } else { - combinations = group1Count * group2Count; - updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])]; + // Keep the latest fallback logic for boxed or F + const group1Count = group1.includes('F') ? this.runnerCount : group1.filter(n => typeof n === 'number').length; + const group2Count = group2.includes('F') ? this.runnerCount : group2.filter(n => typeof n === 'number').length; + combinations = isBoxed + ? this.calculatePermutations(group1Count + group2Count) + : group1Count * group2Count; } + updated.numbers = [...group1, '-', ...group2]; updated.total = combinations * value * 10; break; } @@ -92,21 +91,31 @@ export class SelectionService { const dashIndex = numbers.indexOf('-'); const group1 = dashIndex === -1 ? numbers : numbers.slice(0, dashIndex); const group2 = dashIndex === -1 ? [] : numbers.slice(dashIndex + 1); - const group1Count = group1.includes('F') ? this.runnerCount : group1.filter(n => typeof n === 'number').length; - const group2Count = group2.includes('F') ? this.runnerCount : group2.filter(n => typeof n === 'number').length; let combinations = 0; - if (isBoxed) { - const allNums = [...group1, ...group2].filter(n => typeof n === 'number') as number[]; - const uniqueCount = group1.includes('F') || group2.includes('F') ? this.runnerCount : new Set(allNums).size; - combinations = uniqueCount >= 2 ? this.calculateCombinations(uniqueCount) : 0; - updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])]; + if (!isBoxed && !group1.includes('F') && !group2.includes('F')) { + const group1Numbers = group1.filter(n => typeof n === 'number') as number[]; + const group2Numbers = group2.filter(n => typeof n === 'number') as number[]; + const pairSet = new Set(); + for (const a of group1Numbers) { + for (const b of group2Numbers) { + if (a === b) continue; + const key = a < b ? `${a},${b}` : `${b},${a}`; + pairSet.add(key); + } + } + combinations = pairSet.size; } else { - combinations = (group1Count * group2Count) ; - updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])]; + // Keep latest logic for boxed/F + const group1Count = group1.includes('F') ? this.runnerCount : group1.filter(n => typeof n === 'number').length; + const group2Count = group2.includes('F') ? this.runnerCount : group2.filter(n => typeof n === 'number').length; + combinations = isBoxed + ? this.calculateCombinations(group1Count + group2Count) + : group1Count * group2Count; } + updated.numbers = [...group1, '-', ...group2]; updated.total = combinations * value * 10; break; } @@ -116,29 +125,33 @@ export class SelectionService { .map((n, idx) => (n === '-' ? idx : -1)) .filter(idx => idx !== -1); - if (dashIndices.length < 2 && !isBoxed) break; - - const group1 = dashIndices.length > 0 ? numbers.slice(0, dashIndices[0]) : numbers; - const group2 = dashIndices.length > 0 ? numbers.slice(dashIndices[0] + 1, dashIndices[1] || numbers.length) : []; - const group3 = dashIndices.length > 1 ? numbers.slice(dashIndices[1] + 1) : []; + const group1 = numbers.slice(0, dashIndices[0]); + const group2 = numbers.slice(dashIndices[0] + 1, dashIndices[1]); + const group3 = numbers.slice(dashIndices[1] + 1); let combinations = 0; - if (isBoxed) { - if (numbers.includes('F')) { - combinations = this.calculatePermutationsN(this.runnerCount, 3); - } else { - const allNums = [...group1, ...group2, ...group3].filter(n => typeof n === 'number') as number[]; - combinations = allNums.length >= 3 ? this.calculatePermutationsN(allNums.length, 3) : 0; + if (!isBoxed && !numbers.includes('F')) { + const group1Nums = group1.filter(n => typeof n === 'number') as number[]; + const group2Nums = group2.filter(n => typeof n === 'number') as number[]; + const group3Nums = group3.filter(n => typeof n === 'number') as number[]; + for (const i of group1Nums) { + for (const j of group2Nums) { + if (i === j) continue; + for (const k of group3Nums) { + if (i === k || j === k) continue; + combinations++; + } + } } } else { - const group1Count = group1.includes('F') ? this.runnerCount : group1.filter(n => typeof n === 'number').length; - const group2Count = group2.includes('F') ? this.runnerCount : group2.filter(n => typeof n === 'number').length; - const group3Count = group3.includes('F') ? this.runnerCount : group3.filter(n => typeof n === 'number').length; - combinations = group1Count * group2Count * group3Count; + // Keep fallback logic + combinations = isBoxed + ? this.calculatePermutationsN(numbers.includes('F') ? this.runnerCount : numbers.filter(n => typeof n === 'number').length, 3) + : this.runnerCount * this.runnerCount * this.runnerCount; // fallback approximation } - updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : []), ...(group3.length ? ['-', ...group3] : [])]; + updated.numbers = [...group1, '-', ...group2, '-', ...group3]; updated.total = combinations * value * 10; break; } @@ -148,7 +161,6 @@ export class SelectionService { case 'JKP': { const legs = this.splitToLegs(numbers, this.getLegCount(label)); const requiredLegs = this.getLegCount(label); - const legCounts = legs.map(leg => leg.includes('F') ? this.runnerCount : leg.filter(n => typeof n === 'number').length); const filledLegs = legs.filter(leg => leg.length > 0).length; @@ -223,15 +235,9 @@ export class SelectionService { } } - // Push the last leg if it has numbers - if (currentLeg.length > 0) { - result.push([...currentLeg]); - } + if (currentLeg.length > 0) result.push([...currentLeg]); - // Fill remaining legs with empty arrays if needed - while (result.length < legCount) { - result.push([]); - } + while (result.length < legCount) result.push([]); return result.slice(0, legCount); } @@ -244,4 +250,4 @@ export class SelectionService { default: return 3; } } -} \ No newline at end of file +}