fix : field is working 1st 6
This commit is contained in:
parent
f6b8dba352
commit
2a3af535aa
@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { SharedStateService } from '../../service/shared-state.service'; // Corrected path
|
||||
import { SharedStateService } from '../../service/shared-state.service';
|
||||
|
||||
export interface SelectionData {
|
||||
label: string;
|
||||
@ -54,7 +54,8 @@ export class SelectionService {
|
||||
case 'SHP':
|
||||
case 'THP':
|
||||
case 'PLC':
|
||||
case 'SHW': {
|
||||
case 'SHW':
|
||||
case 'WSP': {
|
||||
if (numbers.includes('F')) {
|
||||
updated.total = this.runnerCount * value * 10;
|
||||
} else {
|
||||
@ -63,7 +64,8 @@ export class SelectionService {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'FOR': {
|
||||
case 'FOR':
|
||||
case 'EXA': {
|
||||
const dashIndex = numbers.indexOf('-');
|
||||
const group1 = dashIndex === -1 ? numbers : numbers.slice(0, dashIndex);
|
||||
const group2 = dashIndex === -1 ? [] : numbers.slice(dashIndex + 1);
|
||||
@ -74,29 +76,12 @@ export class SelectionService {
|
||||
|
||||
if (isBoxed) {
|
||||
const allNums = [...group1, ...group2].filter(n => typeof n === 'number') as number[];
|
||||
const uniqueCount = new Set(allNums).size + (group1.includes('F') || group2.includes('F') ? this.runnerCount : 0);
|
||||
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];
|
||||
updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])];
|
||||
} else {
|
||||
if (group1.includes('F') && group2.includes('F')) {
|
||||
combinations = this.runnerCount * (this.runnerCount - 1); // nP2 for dynamic runners
|
||||
} else if (group1.includes('F') || group2.includes('F')) {
|
||||
const nonFieldGroup = group1.includes('F') ? group2 : group1;
|
||||
const nonFieldNumbers = nonFieldGroup.filter(n => typeof n === 'number') as number[];
|
||||
combinations = this.runnerCount * nonFieldNumbers.length;
|
||||
if (nonFieldNumbers.length > 0) {
|
||||
combinations -= nonFieldNumbers.length; // Subtract overlapping runners
|
||||
}
|
||||
} else {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
updated.numbers = [...group1, '-', ...group2];
|
||||
combinations = group1Count * group2Count;
|
||||
updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])];
|
||||
}
|
||||
|
||||
updated.total = combinations * value * 10;
|
||||
@ -107,47 +92,21 @@ 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 group1_is_field = group1.includes('F');
|
||||
const group2_is_field = group2.includes('F');
|
||||
const group1Numbers = group1.filter(n => typeof n === 'number') as number[];
|
||||
const group2Numbers = group2.filter(n => typeof n === 'number') as number[];
|
||||
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 = new Set(allNums).size + (group1_is_field || group2_is_field ? this.runnerCount : 0);
|
||||
combinations = uniqueCount >= 2 ? (uniqueCount * (uniqueCount - 1)) / 2 : 0;
|
||||
} else if (group1_is_field && group2_is_field) {
|
||||
combinations = (this.runnerCount * (this.runnerCount - 1)) / 2; // C(n,2)
|
||||
} else if (group1_is_field || group2_is_field) {
|
||||
const fieldSide = group1_is_field ? group1Numbers : group2Numbers;
|
||||
const nonFieldNumbers = (group1_is_field ? group2 : group1).filter(n => typeof n === 'number') as number[];
|
||||
const pairSet = new Set<string>();
|
||||
const fieldNumbers = fieldSide.length > 0 ? fieldSide : Array.from({ length: this.runnerCount }, (_, i) => i + 1);
|
||||
for (let j of nonFieldNumbers) {
|
||||
for (let i of fieldNumbers) {
|
||||
if (i !== j) {
|
||||
let min = Math.min(i, j);
|
||||
let max = Math.max(i, j);
|
||||
pairSet.add(`${min},${max}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
combinations = pairSet.size;
|
||||
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] : [])];
|
||||
} else {
|
||||
const pairSet = new Set<string>();
|
||||
for (let a of group1Numbers) {
|
||||
for (let b of group2Numbers) {
|
||||
if (a === b) continue;
|
||||
let key = a < b ? `${a},${b}` : `${b},${a}`;
|
||||
pairSet.add(key);
|
||||
}
|
||||
}
|
||||
combinations = pairSet.size;
|
||||
combinations = (group1Count * group2Count) ;
|
||||
updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : [])];
|
||||
}
|
||||
|
||||
updated.numbers = [...group1, '-', ...group2];
|
||||
updated.total = combinations * value * 10;
|
||||
break;
|
||||
}
|
||||
@ -173,21 +132,10 @@ export class SelectionService {
|
||||
combinations = allNums.length >= 3 ? this.calculatePermutationsN(allNums.length, 3) : 0;
|
||||
}
|
||||
} else {
|
||||
const runners = Array.from({ length: this.runnerCount }, (_, i) => i + 1);
|
||||
const group1Vals = group1.includes('F') ? runners : group1.filter(n => typeof n === 'number') as number[];
|
||||
const group2Vals = group2.includes('F') ? runners : group2.filter(n => typeof n === 'number') as number[];
|
||||
const group3Vals = group3.includes('F') ? runners : group3.filter(n => typeof n === 'number') as number[];
|
||||
|
||||
combinations = 0;
|
||||
for (const i of group1Vals) {
|
||||
for (const j of group2Vals) {
|
||||
if (i === j) continue;
|
||||
for (const k of group3Vals) {
|
||||
if (i === k || j === k) continue;
|
||||
combinations++;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
updated.numbers = [...group1, ...(group2.length ? ['-', ...group2] : []), ...(group3.length ? ['-', ...group3] : [])];
|
||||
@ -195,54 +143,6 @@ export class SelectionService {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'EXA': {
|
||||
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 = new Set(allNums).size + (group1.includes('F') || group2.includes('F') ? this.runnerCount : 0);
|
||||
combinations = uniqueCount >= 2 ? this.calculatePermutations(uniqueCount) : 0;
|
||||
} else {
|
||||
if (group1.includes('F') && group2.includes('F')) {
|
||||
combinations = this.runnerCount * (this.runnerCount - 1);
|
||||
} else if (group1.includes('F') || group2.includes('F')) {
|
||||
const nonFieldGroup = group1.includes('F') ? group2 : group1;
|
||||
const nonFieldNumbers = nonFieldGroup.filter(n => typeof n === 'number') as number[];
|
||||
combinations = this.runnerCount * nonFieldNumbers.length;
|
||||
if (nonFieldNumbers.length > 0) {
|
||||
combinations -= nonFieldNumbers.length;
|
||||
}
|
||||
} else {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updated.numbers = [...group1, '-', ...group2];
|
||||
updated.total = combinations * value * 10;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'WSP': {
|
||||
if (numbers.includes('F')) {
|
||||
updated.total = this.runnerCount * value * 10;
|
||||
} else {
|
||||
updated.total = numbers.filter(n => typeof n === 'number').length * value * 10;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'TRE':
|
||||
case 'MJP':
|
||||
case 'JKP': {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user