fix : QUI logic is working with and without box section

This commit is contained in:
karthik 2025-07-28 23:49:17 +05:30
parent c5edb09cd0
commit 1be559a552

View File

@ -1,4 +1,3 @@
// ✅ Final SelectionService.ts with strict QUI logic
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@ -74,21 +73,32 @@ export class SelectionService {
const group2 = updated.numbers.slice(dashIndex + 1).filter(n => typeof n === 'number') as number[];
let combinations = 0;
const set1 = new Set(group1);
const set2 = new Set(group2);
const uniqueUnion = new Set([...group1, ...group2]);
if (isBoxed) {
const uniq = Array.from(new Set([...group1, ...group2]));
combinations = this.calculateCombinations(uniq.length); // nC2
updated.numbers = [...uniq, '-', ...uniq];
} else {
for (const a of group1) {
for (const b of group2) {
if (a !== b) combinations++;
}
}
updated.numbers = [...group1, '-', ...group2];
function setsAreEqual(a: Set<number>, b: Set<number>): boolean {
if (a.size !== b.size) return false;
for (let v of a) if (!b.has(v)) return false;
return true;
}
updated.total = combinations * value * 10;
if (isBoxed || setsAreEqual(set1, set2)) {
combinations = uniqueUnion.size >= 2 ? (uniqueUnion.size * (uniqueUnion.size - 1)) / 2 : 0;
} else {
const pairSet = new Set<string>();
for (let a of set1) {
for (let b of set2) {
if (a === b) continue;
let key = a < b ? `${a},${b}` : `${b},${a}`;
pairSet.add(key);
}
}
combinations = pairSet.size;
}
updated.numbers = [...group1, '-', ...group2];
updated.total = combinations * value * 10; // Value multiplier as per your code (10x)
break;
}