Skip to content

Commit

Permalink
heuristics progress
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Sep 24, 2024
1 parent 6f2fbbc commit 71a90f9
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 42 deletions.
71 changes: 43 additions & 28 deletions src/components/sections/results/table/ResultTableRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,52 @@ const ResultTableRow = ({
</Typography>
) : null}
</TableCell>
{padCellArray(
maxSlotsLength,
character.gear.map((affix, index) => {
let textDecoration;
if (exoticRarity(affix, index) && mostCommonRarity !== 'exotic')
textDecoration = 'underline dotted #ffa405';
if (!exoticRarity(affix, index) && mostCommonRarity !== 'ascended')
textDecoration = 'underline dotted #fb3e8d';
{character.gear.length > 1 ? (
padCellArray(
maxSlotsLength,
character.gear.map((affix, index) => {
let textDecoration;
if (exoticRarity(affix, index) && mostCommonRarity !== 'exotic')
textDecoration = 'underline dotted #ffa405';
if (!exoticRarity(affix, index) && mostCommonRarity !== 'ascended')
textDecoration = 'underline dotted #fb3e8d';

const affixFragments = affix.split(/(?=[A-Z])/).filter((fragment) => fragment !== 'And');
const multiWordAffix = affixFragments.length > 1;
const affixFragments = affix
.split(/(?=[A-Z])/)
.filter((fragment) => fragment !== 'And');
const multiWordAffix = affixFragments.length > 1;

const shortAffix = affixFragments
.map((fragment) => fragment.slice(0, multiWordAffix ? 3 : 4))
.join('');
const shortAffix = affixFragments
.map((fragment) => fragment.slice(0, multiWordAffix ? 3 : 4))
.join('');

return (
<TableCell align="center" padding="none">
<Typography
style={{
fontWeight: 300,
fontSize: '1rem',
textDecoration,
color: mostCommonAffix && mostCommonAffix !== affix ? '#00cccc' : 'inherit',
}}
>
{shortAffix}
</Typography>
</TableCell>
);
}),
return (
<TableCell align="center" padding="none">
<Typography
style={{
fontWeight: 300,
fontSize: '1rem',
textDecoration,
color: mostCommonAffix && mostCommonAffix !== affix ? '#00cccc' : 'inherit',
}}
>
{shortAffix}
</Typography>
</TableCell>
);
}),
)
) : (
<TableCell align="center" padding="none" colSpan={14}>
<Typography
style={{
fontWeight: 300,
fontSize: '1rem',
}}
>
{character.gear[0]}
</Typography>
</TableCell>
)}
{padCellArray(
2,
Expand Down
2 changes: 2 additions & 0 deletions src/state/optimizer-parallel/optimizerSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export function createSettings(reduxState: RootState): Settings {
secondaryMaxInfusions,
infusionMode,
slots,
affixes,
affixesArray,
identicalArmor,
identicalRing,
Expand Down Expand Up @@ -140,6 +141,7 @@ export function createSettings(reduxState: RootState): Settings {
secondaryInfusion,
secondaryMaxInfusions,
infusionMode,
affixes,
slots,
affixesArray,
identicalArmor,
Expand Down
60 changes: 60 additions & 0 deletions src/state/optimizer/combinatorics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable id-length */
/* eslint-disable import/prefer-default-export */

// warning: not optimized
function binomialCoefficient(n: number, k: number) {
let result = 1;
for (let i = 1; i <= k; i++) {
result *= (n + 1 - i) / i;
}
return Math.round(result);
}

/**
* Generates every integer partition of n of exactly length k.
* Also known as the stars and bars problem.
*
* @example
* console.log([...iteratePartitions(5, 3)])
*
* // [
* // [0, 0, 5],
* // [0, 1, 4],
* // [0, 2, 3],
* // ...
* // [4, 1, 0],
* // [5, 0, 0]
* // ]
*
* @param {number} ballsN - total items to partition (n)
* @param {number} cupsK - partitions (k)
* @param {boolean} mutate - whether to repeatedly yield references to the same mutated array (faster)
* @yields {number[]}
*/
export function* iteratePartitions(
ballsN: number,
cupsK: number,
mutate = false,
): Generator<number[], void, void> {
if (cupsK < 1) throw new Error('invalid iteratePartitions input');

const current: number[] = new Array(cupsK).fill(0);

function* inner(currentCup: number, currentBalls: number): Generator<number[], void, void> {
if (currentCup === cupsK - 1) {
current[currentCup] = currentBalls;
yield mutate ? current : [...current];
} else {
for (let i = 0; i <= currentBalls; i++) {
current[currentCup] = i;
yield* inner(currentCup + 1, currentBalls - i);
}
}
}

yield* inner(0, ballsN);
}

export function iteratePartitionCount(n: number, k: number) {
return binomialCoefficient(k + n - 1, n);
}
Loading

0 comments on commit 71a90f9

Please sign in to comment.