diff --git a/markdown/bitburner.codingcontractobject.md b/markdown/bitburner.codingcontractobject.md index 8c1cfb188..23a451670 100644 --- a/markdown/bitburner.codingcontractobject.md +++ b/markdown/bitburner.codingcontractobject.md @@ -14,6 +14,7 @@ export type CodingContractObject = { data: CodingContractSignatures[T][0]; submit: (answer: CodingContractSignatures[T][1] | string) => string; description: string; + difficulty: number; numTriesRemaining: () => number; }; }[keyof CodingContractSignatures]; diff --git a/src/CodingContract/ContractGenerator.ts b/src/CodingContract/ContractGenerator.ts index aea7714e0..64cd6099a 100644 --- a/src/CodingContract/ContractGenerator.ts +++ b/src/CodingContract/ContractGenerator.ts @@ -70,17 +70,20 @@ export function tryGeneratingRandomContract(numberOfTries: number): void { } export function generateRandomContract(): void { - // First select a random problem type - const problemType = getRandomProblemType(); - - // Then select a random reward type. 'Money' will always be the last reward type - const reward = getRandomReward(); - // Choose random server const randServer = getRandomServer(); if (randServer === null) { return; } + // Then select a random reward type. 'Money' will always be the last reward type + const reward = getRandomReward(); + + // Finally select a random problem type. + // Difficulty is capped to not overwhelm a new player. + const totalSFs = [...Player.sourceFiles].reduce((total, [__bn, lvl]) => (total += lvl), 0); + const maxDif = 2 * totalSFs + 1; + + const problemType = getRandomProblemType(maxDif); const contractFn = getRandomFilename(randServer, reward); const contract = new CodingContract(contractFn, problemType, reward); @@ -179,8 +182,8 @@ function sanitizeRewardType(rewardType: CodingContractRewardType): CodingContrac return type; } -function getRandomProblemType(): CodingContractName { - const problemTypes = Object.values(CodingContractName); +function getRandomProblemType(maxDif = 10): CodingContractName { + const problemTypes = Object.values(CodingContractName).filter((x) => CodingContractTypes[x].difficulty <= maxDif); const randIndex = getRandomIntInclusive(0, problemTypes.length - 1); return problemTypes[randIndex]; diff --git a/src/CodingContract/contracts/AlgorithmicStockTrader.ts b/src/CodingContract/contracts/AlgorithmicStockTrader.ts index 898f27200..ea89737c6 100644 --- a/src/CodingContract/contracts/AlgorithmicStockTrader.ts +++ b/src/CodingContract/contracts/AlgorithmicStockTrader.ts @@ -96,7 +96,7 @@ export const algorithmicStockTrader: Pick< "If no profit can be made, then the answer should be 0.", ].join(" "); }, - difficulty: 5, + difficulty: 4, generate: (): number[] => { const len: number = getRandomIntInclusive(3, 50); const arr: number[] = []; diff --git a/src/CodingContract/contracts/ArrayJumpingGame.ts b/src/CodingContract/contracts/ArrayJumpingGame.ts index d1943e39b..71673397e 100644 --- a/src/CodingContract/contracts/ArrayJumpingGame.ts +++ b/src/CodingContract/contracts/ArrayJumpingGame.ts @@ -21,7 +21,7 @@ export const arrayJumpingGame: Pick< "Your answer should be submitted as 1 or 0, representing true and false respectively.", ].join(" "); }, - difficulty: 2.5, + difficulty: 2, generate: (): number[] => { const len: number = getRandomIntInclusive(3, 25); const arr: number[] = []; diff --git a/src/CodingContract/contracts/HammingCode.ts b/src/CodingContract/contracts/HammingCode.ts index 340ced8a8..e09831e09 100644 --- a/src/CodingContract/contracts/HammingCode.ts +++ b/src/CodingContract/contracts/HammingCode.ts @@ -8,7 +8,7 @@ export const hammingCode: Pick< CodingContractName.HammingCodesEncodedBinaryToInteger | CodingContractName.HammingCodesIntegerToEncodedBinary > = { [CodingContractName.HammingCodesIntegerToEncodedBinary]: { - difficulty: 5, + difficulty: 6, desc: (n: number): string => { return [ "You are given the following decimal value: \n", @@ -43,7 +43,7 @@ export const hammingCode: Pick< validateAnswer: (ans): ans is string => typeof ans === "string", }, [CodingContractName.HammingCodesEncodedBinaryToInteger]: { - difficulty: 8, + difficulty: 9, desc: (n: string): string => { return [ "You are given the following encoded binary string: \n", diff --git a/src/CodingContract/contracts/TotalWaysToSum.ts b/src/CodingContract/contracts/TotalWaysToSum.ts index 58c162b45..685c986ae 100644 --- a/src/CodingContract/contracts/TotalWaysToSum.ts +++ b/src/CodingContract/contracts/TotalWaysToSum.ts @@ -18,7 +18,7 @@ export const totalWaysToSum: Pick< "two positive integers?", ].join(" "); }, - difficulty: 1.5, + difficulty: 1, generate: (): number => { return getRandomIntInclusive(8, 100); }, diff --git a/src/Documentation/doc/basic/codingcontracts.md b/src/Documentation/doc/basic/codingcontracts.md index db45dfc06..9446b4ec5 100644 --- a/src/Documentation/doc/basic/codingcontracts.md +++ b/src/Documentation/doc/basic/codingcontracts.md @@ -8,7 +8,7 @@ They can be accessed through the [Terminal](terminal.md) or through [Scripts](sc Each contract has a limited number of attempts. If you provide the wrong answer too many times and exceed the number of attempts, the contract will self destruct (delete itself). -Currently, Coding Contracts are randomly generated and spawned over time. +Coding Contracts are randomly generated and spawn over time. Initially, you'll only see a small range of the easier contracts, but as you progress further through the game more challenging ones will unlock. They can appear on any [server](servers.md) (including your home computer), except for your purchased [servers](servers.md). ## Running in Terminal @@ -27,6 +27,7 @@ Interacting with Coding Contracts via the [Terminal](terminal.md) can be tedious Consider using the [API](https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.codingcontract.md) to automate various aspects of your solution. For example, some contracts have long solutions while others have even longer solutions. You might want to use the [API](https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.codingcontract.md) to automate the process of submitting your solution rather than copy and paste a long solution into an answer box. +The [Coding Contract API](https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.codingcontract.md) can also be used to find out useful information about a contract including the number of attempts you have left, the type of contract and its difficulty. However, using the [API](https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.codingcontract.md) comes at a cost. Like most functions in other APIs, almost all of the functions in the [Coding Contract API](https://github.com/bitburner-official/bitburner-src/blob/stable/markdown/bitburner.codingcontract.md) have a RAM cost. @@ -67,7 +68,6 @@ There are currently four possible rewards for solving a Coding Contract: - Money The `amount` of the reward varies based on the difficulty of the problem posed by the Coding Contract. -There is no way to know what a Coding Contract's exact reward will be until it is solved. ## Notes diff --git a/src/NetscriptFunctions/CodingContract.ts b/src/NetscriptFunctions/CodingContract.ts index 87e4e1da3..5afc2dbbd 100644 --- a/src/NetscriptFunctions/CodingContract.ts +++ b/src/NetscriptFunctions/CodingContract.ts @@ -92,7 +92,6 @@ export function NetscriptCodingContract(): InternalAPI { const filename = helpers.string(ctx, "filename", _filename); const host = _host ? helpers.string(ctx, "host", _host) : ctx.workerScript.hostname; const contract = getCodingContract(ctx, host, filename); - return structuredClone(contract.getData()); }, getContract: (ctx) => (_filename, _host?) => { @@ -109,6 +108,7 @@ export function NetscriptCodingContract(): InternalAPI { return attemptContract(ctx, server, contract, answer); }, description: contract.getDescription(), + difficulty: contract.getDifficulty(), numTriesRemaining: () => { helpers.checkEnvFlags(ctx); return contract.getMaxNumTries() - contract.tries; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index f6ca52bf4..6245e1b13 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -8780,6 +8780,7 @@ export type CodingContractObject = { data: CodingContractSignatures[T][0]; submit: (answer: CodingContractSignatures[T][1] | string) => string; description: string; + difficulty: number; numTriesRemaining: () => number; }; }[keyof CodingContractSignatures];