Skip to content

Commit

Permalink
[Automated] Merge dev into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored May 11, 2024
2 parents dc96341 + 133ed74 commit f5769ed
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dist/CookieMonster.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonster.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonsterDev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonsterDev.js.map

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions src/Disp/HelperFunctions/CalculateLuckyLevels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
const SPECIAL_DIGIT = 7;

/**
* Count the number of 7s in any number
* @param {number} number The number to count sevens for
* @returns {number} The number of 7s in the provided number
*/
export function CountSevens(number) {
return String(number).split(String(SPECIAL_DIGIT)).length - 1;
}

/**
* Calculate the delta for the next number where the given digit is a 7
* @param {number} number The starting number to calculate the delta for
* @param {number} digitPlace 1 for ones place, 10 for tens place, 100 for hundreds place, etc
* @returns {number} The calculated delta
*/
export function CalculateSevenDelta(number, digitPlace) {
const target = SPECIAL_DIGIT * digitPlace;
const modulus = digitPlace * 10;

let delta = target - (number % modulus) + (number % digitPlace);
if (delta < 0) delta += modulus;

return delta;
}

/**
* This function calculates each of the next "lucky" prestige levels
* @param {number} currentLevel The user's prestige level, including levels earned since the last ascension
* @returns {{number}, {number}, {number}} luckyDigit, luckyNumber, luckyPayout The next eligible level for each upgrade
*/
export default function CalculateLuckyLevels(currentLevel) {
const result = {};
let sevenCount = CountSevens(currentLevel);
const numberOfDigits = String(currentLevel).length;

if (sevenCount >= 1) {
result.luckyDigit = currentLevel;
if (sevenCount >= 2) {
result.luckyNumber = currentLevel;
if (sevenCount >= 4) {
result.luckyPayout = currentLevel;
return result;
}
}
}

// Consider only top 15 digits if it is big number
let localLevel;
if (numberOfDigits >= 16) {
localLevel = Math.ceil(currentLevel / 10 ** (numberOfDigits - 15));
} else {
localLevel = currentLevel;
}
sevenCount = CountSevens(localLevel);

if (result.luckyDigit === undefined) {
if (sevenCount < 1) {
const delta = CalculateSevenDelta(localLevel, 1);

localLevel += delta;
sevenCount = CountSevens(localLevel);
}

result.luckyDigit = localLevel;
if (numberOfDigits >= 16) {
result.luckyDigit *= 10 ** Number(numberOfDigits - 15);
}
}

if (result.luckyNumber === undefined) {
while (sevenCount < 2) {
let delta = CalculateSevenDelta(localLevel, 1);
if (delta === 0) delta = CalculateSevenDelta(localLevel, 10);

localLevel += delta;
sevenCount = CountSevens(localLevel);
}

result.luckyNumber = localLevel;
if (numberOfDigits >= 16) {
result.luckyNumber *= 10 ** Number(numberOfDigits - 15);
}
}

let digitPlace = 1;
while (sevenCount < 4) {
const delta = CalculateSevenDelta(localLevel, digitPlace);
if (delta === 0) {
digitPlace *= 10;
} else {
localLevel += delta;
sevenCount = CountSevens(localLevel);
}
}

result.luckyPayout = localLevel;
if (numberOfDigits >= 16) {
result.luckyPayout *= 10 ** Number(numberOfDigits - 15);
}

return result;
}
50 changes: 26 additions & 24 deletions src/Disp/MenuSections/Statistics/CreateStatsSections.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
CacheWrinklersTotal,
} from '../../../Cache/VariablesAndData';
import ResetBonus from '../../../Sim/SimulationEvents/ResetAscension';
import CalculateLuckyLevels from '../../HelperFunctions/CalculateLuckyLevels';
import GetCPS from '../../HelperFunctions/GetCPS';
import GetWrinkConfigBank from '../../HelperFunctions/GetWrinkConfigBank';
import { ColourGreen, ColourRed, ColourTextPre } from '../../VariablesAndData';
Expand Down Expand Up @@ -606,46 +607,47 @@ export function PrestigeSection() {
const currentPrestige = Math.floor(Game.HowMuchPrestige(Game.cookiesReset));
const willHave = Math.floor(Game.HowMuchPrestige(Game.cookiesReset + Game.cookiesEarned));
const willGet = willHave - currentPrestige;
const { luckyDigit, luckyNumber, luckyPayout } = CalculateLuckyLevels(willHave);
if (!Game.Has('Lucky digit')) {
let delta7 = 7 - (willHave % 10);
if (delta7 < 0) delta7 += 10;
const next7Reset = willGet + delta7;
const next7Total = willHave + delta7;
const frag7 = document.createDocumentFragment();
frag7.appendChild(
const luckyDigitDelta = luckyDigit - willHave;
const luckyDigitReset = willGet + luckyDigitDelta;
const fragLuckyDigit = document.createDocumentFragment();
fragLuckyDigit.appendChild(
document.createTextNode(
`${next7Total.toLocaleString()} / ${next7Reset.toLocaleString()} (+${delta7})`,
`${luckyDigit.toLocaleString()} / ${luckyDigitReset.toLocaleString()} (+${luckyDigitDelta})`,
),
);
section.appendChild(StatsListing('basic', 'Next "Lucky Digit" (total / reset)', frag7));
section.appendChild(
StatsListing('basic', 'Next "Lucky Digit" (total / reset)', fragLuckyDigit),
);
}

if (!Game.Has('Lucky number')) {
let delta777 = 777 - (willHave % 1000);
if (delta777 < 0) delta777 += 1000;
const next777Reset = willGet + delta777;
const next777Total = willHave + delta777;
const frag777 = document.createDocumentFragment();
frag777.appendChild(
const luckyNumberDelta = luckyNumber - willHave;
const luckyNumberReset = willGet + luckyNumberDelta;
const fragLuckyNumber = document.createDocumentFragment();
fragLuckyNumber.appendChild(
document.createTextNode(
`${next777Total.toLocaleString()} / ${next777Reset.toLocaleString()} (+${delta777})`,
`${luckyNumber.toLocaleString()} / ${luckyNumberReset.toLocaleString()} (+${luckyNumberDelta})`,
),
);
section.appendChild(StatsListing('basic', 'Next "Lucky Number" (total / reset)', frag777));
section.appendChild(
StatsListing('basic', 'Next "Lucky Number" (total / reset)', fragLuckyNumber),
);
}

if (!Game.Has('Lucky payout')) {
let delta777777 = 777777 - (willHave % 1000000);
if (delta777777 < 0) delta777777 += 1000000;
const next777777Reset = willGet + delta777777;
const next777777Total = willHave + delta777777;
const frag777777 = document.createDocumentFragment();
frag777777.appendChild(
const luckyPayoutDelta = luckyPayout - willHave;
const luckyPayoutReset = willGet + luckyPayoutDelta;
const fragLuckyPayout = document.createDocumentFragment();
fragLuckyPayout.appendChild(
document.createTextNode(
`${next777777Total.toLocaleString()} / ${next777777Reset.toLocaleString()} (+${delta777777})`,
`${luckyPayout.toLocaleString()} / ${luckyPayoutReset.toLocaleString()} (+${luckyPayoutDelta})`,
),
);
section.appendChild(StatsListing('basic', 'Next "Lucky Payout" (total / reset)', frag777777));
section.appendChild(
StatsListing('basic', 'Next "Lucky Payout" (total / reset)', fragLuckyPayout),
);
}

return section;
Expand Down
77 changes: 77 additions & 0 deletions test/t_Disp/t_CalculateLuckyLevels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';

import CalculateLuckyLevels, {
CalculateSevenDelta,
CountSevens,
} from '../../src/Disp/HelperFunctions/CalculateLuckyLevels';

describe('CountSevens', () => {
const examples = [
{ input: 1234567890, output: 1 },
{ input: 7777777777, output: 10 },
{ input: 1111111111, output: 0 },
{ input: 7897897897, output: 4 },
];

examples.forEach((example) => {
it(`Counts sevens in ${example.input}`, () => {
expect(CountSevens(example.input)).to.equal(example.output);
});
});
});

describe('CalculateSevenDelta', () => {
const examples = [
{ number: 123, digit: 1, output: 4 },
{ number: 123, digit: 10, output: 50 },
{ number: 123, digit: 100, output: 600 },
{ number: 123, digit: 1000, output: 7000 },
{ number: 7777, digit: 1, output: 0 },
{ number: 7777, digit: 10, output: 0 },
{ number: 7777, digit: 100, output: 0 },
{ number: 7777, digit: 1000, output: 0 },
{ number: 9999, digit: 1, output: 8 },
{ number: 9999, digit: 10, output: 80 },
{ number: 9999, digit: 100, output: 800 },
{ number: 9999, digit: 1000, output: 8000 },
];

examples.forEach((example) => {
it(`Calculates delta from ${example.number} to the next 7 in the ${example.digit}s digit`, () => {
expect(CalculateSevenDelta(example.number, example.digit)).to.equal(example.output);
});
});
});

describe('CalculateLuckyLevels', () => {
const examples = [
{ input: 0, luckyDigit: 7, luckyNumber: 77, luckyPayout: 7777 },
{ input: 123, luckyDigit: 127, luckyNumber: 177, luckyPayout: 7777 },
{ input: 77777, luckyDigit: 77777, luckyNumber: 77777, luckyPayout: 77777 },
{ input: 799999, luckyDigit: 799999, luckyNumber: 800077, luckyPayout: 807777 },
{ input: 999999, luckyDigit: 1000007, luckyNumber: 1000077, luckyPayout: 1007777 },
{
input: 123456789123456789,
luckyDigit: 123456789123456789,
luckyNumber: 123456789123456789,
luckyPayout: 123456789123777000,
},
{
input: 8888888888888888888,
luckyDigit: 8888888888888970000,
luckyNumber: 8888888888889770000,
luckyPayout: 8888888888977770000,
},
];

examples.forEach((example) => {
it(`Calculates the next lucky levels for the starting level ${example.input}`, () => {
expect(CalculateLuckyLevels(example.input)).to.deep.equal({
luckyDigit: example.luckyDigit,
luckyNumber: example.luckyNumber,
luckyPayout: example.luckyPayout,
});
});
});
});

0 comments on commit f5769ed

Please sign in to comment.