fix : FOR logic is working

This commit is contained in:
karthik 2025-07-28 12:46:53 +05:30
parent 2dbee40fd2
commit c8bc66d214
2 changed files with 48 additions and 16 deletions

View File

@ -1,3 +1,4 @@
// ✅ Final SelectionService.ts with strict FOR logic, split from QUI
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@ -43,19 +44,51 @@ export class SelectionService {
updated.total = numbers.length * value * 10;
break;
case 'FOR':
case 'FOR': {
const dashIndex = updated.numbers.indexOf('-');
const group1 = updated.numbers.slice(0, dashIndex).filter(n => typeof n === 'number') as number[];
const group2 = updated.numbers.slice(dashIndex + 1).filter(n => typeof n === 'number') as number[];
let combinations = 0;
if (isBoxed) {
const uniq = Array.from(new Set([...group1, ...group2]));
combinations = this.calculatePermutations(uniq.length); // nP2
updated.numbers = [...uniq, '-', ...uniq];
} else {
for (const a of group1) {
for (const b of group2) {
if (a !== b) combinations++;
}
}
updated.numbers = [...group1, '-', ...group2];
}
updated.total = combinations * value * 10;
break;
}
case 'QUI': {
const dashIndex = updated.numbers.indexOf('-');
const group1 = updated.numbers.slice(0, dashIndex).filter(n => typeof n === 'number') as number[];
const group2 = updated.numbers.slice(dashIndex + 1).filter(n => typeof n === 'number') as number[];
let combinations = group1.length * group2.length;
let combinations = 0;
if (isBoxed) {
combinations = this.calculatePermutations(group1.length + group2.length);
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) {
combinations++;
}
}
updated.numbers = [...group1, '-', ...group2];
}
updated.total = combinations * value * 10;
updated.numbers = [...group1, '-', ...group2];
break;
}
@ -80,17 +113,16 @@ export class SelectionService {
break;
}
case 'TRE': // TBP: 3 legs
case 'MJP': // MJP: 4 legs
case 'JKP': { // JPP: 5 legs
case 'TRE':
case 'MJP':
case 'JKP': {
const legs = this.splitToLegs(updated.numbers, this.getLegCount(label));
const requiredLegs = this.getLegCount(label);
// Calculate partial total if at least second-to-last leg has numbers
const filledLegs = legs.filter(leg => leg.length > 0).length;
if (filledLegs >= requiredLegs - 1) {
// Assume remaining legs have at least 1 horse
const combinations = legs.reduce((acc, leg) => acc * (leg.length || 1), 1);
updated.total = combinations * value * 10; // fUBA = 10
updated.total = combinations * value * 10;
}
break;
}
@ -122,11 +154,11 @@ export class SelectionService {
}
private calculateCombinations(n: number): number {
return n >= 2 ? (n * (n - 1)) / 2 : 0; // nC2
return n >= 2 ? (n * (n - 1)) / 2 : 0;
}
private calculatePermutations(n: number): number {
return n >= 2 ? n * (n - 1) : 0; // nP2
return n >= 2 ? n * (n - 1) : 0;
}
private splitToLegs(numbers: (number | string)[], legCount: number): number[][] {
@ -162,9 +194,9 @@ export class SelectionService {
private getLegCount(label: string): number {
switch (label) {
case 'TRE': return 3; // TBP
case 'MJP': return 4; // MJP
case 'JKP': return 5; // JPP
case 'TRE': return 3;
case 'MJP': return 4;
case 'JKP': return 5;
default: return 3;
}
}

View File

@ -33,7 +33,7 @@ export class TouchPadMenuComponent implements OnInit {
calcDisplay = '';
maxRowsReached: boolean = false;
disabledLabels: string[] = ['SHW', 'SJP'];
disabledLabels: string[] = ['SHW', 'SJP', '.'];
// ✅ Original TAN logic
tanGroupStage = 0;