Skip to content

Commit

Permalink
Readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Jan 11, 2025
1 parent 59145ba commit 5b40442
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion data/mods/gen2/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
this.debug('Pursuit start');
let alreadyAdded = false;
for (const source of this.effectState.sources) {
if (source.speed < pokemon.speed || (source.speed === pokemon.speed && this.random(2) === 0)) {
if (source.speed < pokemon.speed || (source.speed === pokemon.speed && this.randomChance(1, 2))) {
// Destiny Bond ends if the switch action "outspeeds" the attacker, regardless of host
pokemon.removeVolatile('destinybond');
}
Expand Down
2 changes: 1 addition & 1 deletion data/mods/gen5/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Conditions: import('../../../sim/dex-conditions').ModdedConditionDa
// However, just in case, use 1 if it is undefined.
const counter = this.effectState.counter || 1;
if (counter >= 256) {
return this.random(0x100000000) === 0; // 2^32
return this.randomChance(1, 2 ** 32);
}
this.debug("Success chance: " + Math.round(100 / counter) + "%");
return this.randomChance(1, counter);
Expand Down
2 changes: 1 addition & 1 deletion data/mods/gen9ssb/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
const spd = target.getStat('spd', false, true);
const physical = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * atk) / def) / 50);
const special = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * spa) / spd) / 50);
if (physical > special || (physical === special && this.random(2) === 0)) {
if (physical > special || (physical === special && this.randomChance(1, 2))) {
move.category = 'Physical';
move.flags.contact = 1;
}
Expand Down
8 changes: 4 additions & 4 deletions data/moves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7352,7 +7352,7 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = {
isMax: "Snorlax",
self: {
onHit(source) {
if (this.random(2) === 0) return;
if (this.randomChance(1, 2)) return;
for (const pokemon of source.alliesAndSelf()) {
if (pokemon.item) continue;

Expand Down Expand Up @@ -7448,12 +7448,12 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = {
isMax: "Grimmsnarl",
onHit(target) {
if (target.status || !target.runStatusImmunity('slp')) return;
if (this.random(2) === 0) return;
if (this.randomChance(1, 2)) return;
target.addVolatile('yawn');
},
onAfterSubDamage(damage, target) {
if (target.status || !target.runStatusImmunity('slp')) return;
if (this.random(2) === 0) return;
if (this.randomChance(1, 2)) return;
target.addVolatile('yawn');
},
secondary: null,
Expand Down Expand Up @@ -16814,7 +16814,7 @@ export const Moves: import('../sim/dex-moves').MoveDataTable = {
const spd = target.getStat('spd', false, true);
const physical = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * atk) / def) / 50);
const special = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * spa) / spd) / 50);
if (physical > special || (physical === special && this.random(2) === 0)) {
if (physical > special || (physical === special && this.randomChance(1, 2))) {
move.category = 'Physical';
move.flags.contact = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion data/rulesets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2543,7 +2543,7 @@ export const Rulesets: import('../sim/dex-formats').FormatDataTable = {
const spd = target.getStat('spd', false, true);
const physical = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * atk) / def) / 50);
const special = Math.floor(Math.floor(Math.floor(Math.floor(2 * pokemon.level / 5 + 2) * 90 * spa) / spd) / 50);
if (physical > special || (physical === special && this.random(2) === 0)) {
if (physical > special || (physical === special && this.randomChance(1, 2))) {
move.category = 'Physical';
move.flags.contact = 1;
}
Expand Down
24 changes: 12 additions & 12 deletions sim/prng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ export class PRNG {
if (from) from = Math.floor(from);
if (to) to = Math.floor(to);
if (from === undefined) {
return result / 0x100000000;
return result / 2 ** 32;
} else if (!to) {
return Math.floor(result * from / 0x100000000);
return Math.floor(result * from / 2 ** 32);
} else {
return Math.floor(result * (to - from) / 0x100000000) + from;
return Math.floor(result * (to - from) / 2 ** 32) + from;
}
}

Expand Down Expand Up @@ -149,10 +149,10 @@ export class PRNG {
return [
'sodium',
// 32 bits each, 128 bits total (16 bytes)
Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0') +
Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0') +
Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0') +
Math.trunc(Math.random() * 0x100000000).toString(16).padStart(8, '0'),
Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0') +
Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0') +
Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0') +
Math.trunc(Math.random() * 2 ** 32).toString(16).padStart(8, '0'),
];
}
}
Expand Down Expand Up @@ -267,10 +267,10 @@ export class Gen5RNG implements RNG {

static generateSeed(): Gen5RNGSeed {
return [
Math.trunc(Math.random() * 0x10000),
Math.trunc(Math.random() * 0x10000),
Math.trunc(Math.random() * 0x10000),
Math.trunc(Math.random() * 0x10000),
Math.trunc(Math.random() * 2 ** 16),
Math.trunc(Math.random() * 2 ** 16),
Math.trunc(Math.random() * 2 ** 16),
Math.trunc(Math.random() * 2 ** 16),
];
}
}
Expand All @@ -286,7 +286,7 @@ export type Gen3RNGSeed = ['gen3', number];
export class Gen3RNG implements RNG {
seed: number;
constructor(seed: Gen3RNGSeed | null = null) {
this.seed = seed ? seed[1] : Math.trunc(Math.random() * 0x100000000);
this.seed = seed ? seed[1] : Math.trunc(Math.random() * 2 ** 32);
}
getSeed() {
return ['gen3', this.seed];
Expand Down
8 changes: 4 additions & 4 deletions sim/tools/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ export class Runner {
// NOTE: advances this.prng's seed by 4.
private newSeed(): PRNGSeed {
return [
this.prng.random(0x10000),
this.prng.random(0x10000),
this.prng.random(0x10000),
this.prng.random(0x10000),
this.prng.random(2 ** 16),
this.prng.random(2 ** 16),
this.prng.random(2 ** 16),
this.prng.random(2 ** 16),
];
}

Expand Down

0 comments on commit 5b40442

Please sign in to comment.