Skip to content

Commit cb8467e

Browse files
committed
StepChain
1 parent 50a4e09 commit cb8467e

5 files changed

Lines changed: 96 additions & 7 deletions

File tree

src/Data/data.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,14 +801,15 @@
801801
}
802802
},
803803
"stratCategories": ["Best Overall", "Best Active", "Best Semi-Idle", "Best Idle"],
804-
"modes": ["All", "Single sim", "Chain", "Steps", "Amount", "Time", "Time diff."],
805-
"modeInputDescriptions": ["", "", "", "Step length: ", "Amount of pubs (Chain): ", "Total Time: "],
804+
"modes": ["All", "Single sim", "Chain", "Steps", "StepChain", "Amount", "Time", "Time diff."],
805+
"modeInputDescriptions": ["", "", "", "Step length: ", "Step length: ", "Amount of pubs (Chain): ", "Total Time: "],
806806
"modeInputPlaceholder": [
807807
"<sigma> <t1>* [t2]* ... [wsp]* ... [bap]* \n\n*[r/t/m] = rho/tau/total multiplier | default tau\n\nOr: input your save here and click \"Load save\"",
808808
"",
809809
"",
810810
"",
811811
"<Number>",
812+
"<Number>",
812813
"<Hours>",
813814
"<t1> [t1], ... , <t8> [t8] or <wsp> [wsp], ... , <bap> [bap]",
814815
"<t1> [t1], ... , <t8> [t8] or <wsp> [wsp], ... , <bap> [bap]",

src/Sim/parse.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,23 @@ function parseStepSim(): StepSimQuery {
136136
}
137137
}
138138

139+
function parseStepChainSim(): StepChainQuery {
140+
const theory = theorySelector.value as theoryType;
141+
const sigma = parseSigma(isMainTheory(theory));
142+
143+
return {
144+
queryType: "step_chain",
145+
theory: theory,
146+
strat: stratSelector.value,
147+
sigma: sigma,
148+
rho: parseCurrency(currencyInput.value, theory, sigma),
149+
cap: parseCurrency(capInput.value, theory, sigma),
150+
step: parseExponentialValue(modeInput.value),
151+
hardCap: hardCap.checked,
152+
settings: parseSettings()
153+
}
154+
}
155+
139156
function parseSimAll(): SimAllQuery {
140157
const settings = parseSettings();
141158
const str = simAllInputArea.value;
@@ -179,6 +196,7 @@ export function parseQuery(): SimQuery {
179196
case "Single sim": return parseSingleSim();
180197
case "Chain": return parseChainSim();
181198
case "Steps": return parseStepSim();
199+
case "StepChain": return parseStepChainSim();
182200
default: throw "This mode is not supported.";
183201
}
184202
}

src/Sim/simulate.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async function singleSim(query: SingleSimQuery): Promise<SingleSimResponse> {
7474
}
7575
}
7676

77-
async function chainSim(query: ChainSimQuery): Promise<ChainSimResponse> {
77+
async function chainSim(query: ChainSimQuery, doLog = true): Promise<ChainSimResponse> {
7878
let rho = query.rho;
7979
let time = 0;
8080
let lastStrat = "";
@@ -84,7 +84,7 @@ async function chainSim(query: ChainSimQuery): Promise<ChainSimResponse> {
8484

8585
while (rho < query.cap) {
8686
const ts = performance.now();
87-
if (ts - lastLog > 250) {
87+
if (ts - lastLog > 250 && doLog) {
8888
lastLog = ts;
8989
output.textContent = `Simulating ${logToExp(rho, 0)}/${stopStr}`;
9090
await sleep();
@@ -207,11 +207,71 @@ async function simAll(query: SimAllQuery): Promise<SimAllResponse> {
207207
}
208208
}
209209

210+
async function stepChainSim(query: StepChainQuery): Promise<StepSimResponse> {
211+
let rho = query.rho;
212+
const results: simResult[] = [];
213+
const stopStr = logToExp(query.cap);
214+
let lastLog = 0;
215+
216+
while (rho < query.cap - query.step + 0.000001) {
217+
const ts = performance.now();
218+
if (ts - lastLog > 250) {
219+
lastLog = ts;
220+
output.textContent = `Simulating ${logToExp(rho, 0)}/${stopStr}`;
221+
await sleep();
222+
}
223+
224+
const chain_res = await chainSim({
225+
queryType: "chain",
226+
settings: query.settings,
227+
sigma: query.sigma,
228+
rho,
229+
theory: query.theory,
230+
strat: query.strat,
231+
cap: query.cap,
232+
hardCap: query.hardCap
233+
}, false);
234+
if (!global.simulating) break;
235+
236+
let tau_acc = 0;
237+
let time_acc = 0;
238+
let pub_count = 0;
239+
let bestRes = defaultResult();
240+
for (let result of chain_res.results) {
241+
tau_acc += result.deltaTau;
242+
time_acc += result.time;
243+
pub_count++;
244+
const tauH = tau_acc / (time_acc / 3600);
245+
let cur_res: simResult = {
246+
theory: query.theory,
247+
sigma: query.sigma,
248+
lastPub: rho,
249+
pubRho: result.pubRho,
250+
deltaTau: tau_acc,
251+
pubMulti: 1,
252+
strat: pub_count + " pub" + (pub_count > 1 ? "s": ""),
253+
tauH: tauH,
254+
time: time_acc,
255+
boughtVars: []
256+
}
257+
bestRes = getBestResult(bestRes, cur_res);
258+
}
259+
results.push(bestRes);
260+
rho += query.step;
261+
}
262+
263+
return {
264+
responseType: "step",
265+
results: results
266+
}
267+
}
268+
210269
export async function simulate(query: SimQuery): Promise<SimResponse> {
211270
switch (query.queryType) {
212271
case "single": return await singleSim(query);
213272
case "chain": return await chainSim(query);
214273
case "step": return await stepSim(query);
215274
case "all": return await simAll(query);
275+
case "step_chain": return await stepChainSim(query);
216276
}
217277
}

src/UI/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ function modeUpdate(): void {
104104
// Displays the single-theory inputs
105105
if (newMode !== "All" && newMode !== "Time diff.") singleInput.style.display = "grid";
106106
// Displays the cap input for chain/steps mode
107-
if (newMode === "Chain" || newMode === "Steps") capInputWrapper.style.display = "inline";
107+
if (newMode === "Chain" || newMode === "Steps" || newMode === "StepChain") capInputWrapper.style.display = "inline";
108108
// Displays the hard cap input
109-
if (newMode === "Chain") hardCapWrapper.style.display = "block";
109+
if (newMode === "Chain" || newMode == "StepChain") hardCapWrapper.style.display = "block";
110110

111111
// Extra Inputs
112112
if (newMode !== "Single sim" && newMode !== "Time diff." && newMode !== "Chain") extraInputs.style.display = "flex";

src/Utils/global.types.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,17 @@ declare global {
6262
stratType: SettingsSimAllStratsMode;
6363
}
6464

65-
type SimQuery = SingleSimQuery | ChainSimQuery | StepSimQuery | SimAllQuery;
65+
type StepChainQuery = BaseSimQuery & {
66+
queryType: "step_chain"
67+
theory: theoryType
68+
strat: string
69+
rho: number
70+
cap: number
71+
step: number
72+
hardCap: boolean
73+
}
74+
75+
type SimQuery = SingleSimQuery | ChainSimQuery | StepSimQuery | SimAllQuery | StepChainQuery;
6676

6777
type SingleSimResponse = {
6878
responseType: "single";

0 commit comments

Comments
 (0)