mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-09 17:23:53 +01:00
MISC: Rename getRandomArbitrary (#1605)
This commit is contained in:
parent
995e367432
commit
818d7446be
@ -8,7 +8,7 @@ import { interpolate } from "./Difficulty";
|
|||||||
import { GameTimer } from "./GameTimer";
|
import { GameTimer } from "./GameTimer";
|
||||||
import { IMinigameProps } from "./IMinigameProps";
|
import { IMinigameProps } from "./IMinigameProps";
|
||||||
import { KeyHandler } from "./KeyHandler";
|
import { KeyHandler } from "./KeyHandler";
|
||||||
import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary";
|
import { randomInRange } from "../../utils/helpers/randomInRange";
|
||||||
|
|
||||||
interface Difficulty {
|
interface Difficulty {
|
||||||
[key: string]: number;
|
[key: string]: number;
|
||||||
@ -67,7 +67,7 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function makeAnswer(difficulty: Difficulty): string {
|
function makeAnswer(difficulty: Difficulty): string {
|
||||||
const length = getRandomArbitrary(difficulty.min, difficulty.max);
|
const length = randomInRange(difficulty.min, difficulty.max);
|
||||||
let answer = "";
|
let answer = "";
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
if (i > 0) answer += " ";
|
if (i > 0) answer += " ";
|
||||||
|
@ -8,7 +8,7 @@ import { interpolate } from "./Difficulty";
|
|||||||
import { GameTimer } from "./GameTimer";
|
import { GameTimer } from "./GameTimer";
|
||||||
import { IMinigameProps } from "./IMinigameProps";
|
import { IMinigameProps } from "./IMinigameProps";
|
||||||
import { KeyHandler } from "./KeyHandler";
|
import { KeyHandler } from "./KeyHandler";
|
||||||
import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary";
|
import { randomInRange } from "../../utils/helpers/randomInRange";
|
||||||
|
|
||||||
interface Difficulty {
|
interface Difficulty {
|
||||||
[key: string]: number;
|
[key: string]: number;
|
||||||
@ -35,7 +35,7 @@ function generateLeftSide(difficulty: Difficulty): string {
|
|||||||
if (Player.hasAugmentation(AugmentationName.WisdomOfAthena, true)) {
|
if (Player.hasAugmentation(AugmentationName.WisdomOfAthena, true)) {
|
||||||
options.splice(0, 1);
|
options.splice(0, 1);
|
||||||
}
|
}
|
||||||
const length = getRandomArbitrary(difficulty.min, difficulty.max);
|
const length = randomInRange(difficulty.min, difficulty.max);
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
str += options[Math.floor(Math.random() * options.length)];
|
str += options[Math.floor(Math.random() * options.length)];
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { interpolate } from "./Difficulty";
|
|||||||
import { GameTimer } from "./GameTimer";
|
import { GameTimer } from "./GameTimer";
|
||||||
import { IMinigameProps } from "./IMinigameProps";
|
import { IMinigameProps } from "./IMinigameProps";
|
||||||
import { KeyHandler } from "./KeyHandler";
|
import { KeyHandler } from "./KeyHandler";
|
||||||
import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary";
|
import { randomInRange } from "../../utils/helpers/randomInRange";
|
||||||
|
|
||||||
interface Difficulty {
|
interface Difficulty {
|
||||||
[key: string]: number;
|
[key: string]: number;
|
||||||
@ -78,7 +78,7 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement {
|
|||||||
function generateCode(difficulty: Difficulty): Arrow[] {
|
function generateCode(difficulty: Difficulty): Arrow[] {
|
||||||
const arrows: Arrow[] = [leftArrowSymbol, rightArrowSymbol, upArrowSymbol, downArrowSymbol];
|
const arrows: Arrow[] = [leftArrowSymbol, rightArrowSymbol, upArrowSymbol, downArrowSymbol];
|
||||||
const code: Arrow[] = [];
|
const code: Arrow[] = [];
|
||||||
for (let i = 0; i < getRandomArbitrary(difficulty.min, difficulty.max); i++) {
|
for (let i = 0; i < randomInRange(difficulty.min, difficulty.max); i++) {
|
||||||
let arrow = arrows[Math.floor(4 * Math.random())];
|
let arrow = arrows[Math.floor(4 * Math.random())];
|
||||||
while (arrow === code[code.length - 1]) arrow = arrows[Math.floor(4 * Math.random())];
|
while (arrow === code[code.length - 1]) arrow = arrows[Math.floor(4 * Math.random())];
|
||||||
code.push(arrow);
|
code.push(arrow);
|
||||||
|
@ -9,7 +9,7 @@ import { GameTimer } from "./GameTimer";
|
|||||||
import { IMinigameProps } from "./IMinigameProps";
|
import { IMinigameProps } from "./IMinigameProps";
|
||||||
import { KeyHandler } from "./KeyHandler";
|
import { KeyHandler } from "./KeyHandler";
|
||||||
import { isPositiveInteger } from "../../types";
|
import { isPositiveInteger } from "../../types";
|
||||||
import { getRandomArbitrary } from "../../utils/helpers/getRandomArbitrary";
|
import { randomInRange } from "../../utils/helpers/randomInRange";
|
||||||
|
|
||||||
interface Difficulty {
|
interface Difficulty {
|
||||||
[key: string]: number;
|
[key: string]: number;
|
||||||
@ -200,7 +200,7 @@ function generateQuestion(wires: Wire[], difficulty: Difficulty): Question[] {
|
|||||||
|
|
||||||
function generateWires(difficulty: Difficulty): Wire[] {
|
function generateWires(difficulty: Difficulty): Wire[] {
|
||||||
const wires = [];
|
const wires = [];
|
||||||
const numWires = getRandomArbitrary(difficulty.wiresmin, difficulty.wiresmax);
|
const numWires = randomInRange(difficulty.wiresmin, difficulty.wiresmax);
|
||||||
for (let i = 0; i < numWires; i++) {
|
for (let i = 0; i < numWires; i++) {
|
||||||
const wireColors = [colors[Math.floor(Math.random() * colors.length)]];
|
const wireColors = [colors[Math.floor(Math.random() * colors.length)]];
|
||||||
if (Math.random() < 0.15) {
|
if (Math.random() < 0.15) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_number_between_two_values
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#getting_a_random_number_between_two_values
|
||||||
export function getRandomArbitrary(min: number, max: number): number {
|
export function randomInRange(min: number, max: number): number {
|
||||||
if (min > max) {
|
if (min > max) {
|
||||||
throw new Error(`Min is greater than max. Min: ${min}. Max: ${max}.`);
|
throw new Error(`Min is greater than max. Min: ${min}. Max: ${max}.`);
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ import { currentNodeMults } from "../../../src/BitNode/BitNodeMultipliers";
|
|||||||
import { Skill } from "../../../src/Bladeburner/Skill";
|
import { Skill } from "../../../src/Bladeburner/Skill";
|
||||||
import { BladeburnerSkillName } from "../../../src/Enums";
|
import { BladeburnerSkillName } from "../../../src/Enums";
|
||||||
import { PositiveInteger, isPositiveInteger, isPositiveNumber } from "../../../src/types";
|
import { PositiveInteger, isPositiveInteger, isPositiveNumber } from "../../../src/types";
|
||||||
import { getRandomArbitrary } from "../../../src/utils/helpers/getRandomArbitrary";
|
import { randomInRange } from "../../../src/utils/helpers/randomInRange";
|
||||||
import { getRandomIntInclusive } from "../../../src/utils/helpers/getRandomIntInclusive";
|
import { getRandomIntInclusive } from "../../../src/utils/helpers/getRandomIntInclusive";
|
||||||
|
|
||||||
const skill = new Skill({
|
const skill = new Skill({
|
||||||
@ -22,9 +22,9 @@ describe("Test calculateMaxUpgradeCount", function () {
|
|||||||
for (let i = 0; i < 10; ++i) {
|
for (let i = 0; i < 10; ++i) {
|
||||||
skill.baseCost = getRandomIntInclusive(1, 1000);
|
skill.baseCost = getRandomIntInclusive(1, 1000);
|
||||||
for (let j = 0; j < 10; ++j) {
|
for (let j = 0; j < 10; ++j) {
|
||||||
skill.costInc = getRandomArbitrary(1, 1000);
|
skill.costInc = randomInRange(1, 1000);
|
||||||
for (let k = 0; k < 10; ++k) {
|
for (let k = 0; k < 10; ++k) {
|
||||||
currentNodeMults.BladeburnerSkillCost = getRandomArbitrary(1, 1000);
|
currentNodeMults.BladeburnerSkillCost = randomInRange(1, 1000);
|
||||||
for (let m = 0; m < 1e4; ++m) {
|
for (let m = 0; m < 1e4; ++m) {
|
||||||
const currentLevel = getRandomIntInclusive(0, 1e9);
|
const currentLevel = getRandomIntInclusive(0, 1e9);
|
||||||
let count = 0;
|
let count = 0;
|
||||||
@ -56,7 +56,7 @@ describe("Test calculateMaxUpgradeCount", function () {
|
|||||||
|
|
||||||
// Test 2
|
// Test 2
|
||||||
++testCaseCount;
|
++testCaseCount;
|
||||||
const budget = getRandomArbitrary(1e9, 1e50);
|
const budget = randomInRange(1e9, 1e50);
|
||||||
if (!isPositiveNumber(budget)) {
|
if (!isPositiveNumber(budget)) {
|
||||||
throw new Error(`Invalid budget: ${budget}`);
|
throw new Error(`Invalid budget: ${budget}`);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user