Skip to content

Commit

Permalink
Readability (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Jan 10, 2025
1 parent 40cbb50 commit f05a128
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions data/mods/gen5/conditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +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) {
// 2^32 - special-cased because Battle.random(n) can't handle n > 2^16 - 1
return (this.random() * 4294967296 < 1);
return this.random(0x100000000) === 0; // 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 @@ -1248,7 +1248,7 @@ export const Moves: import('../../../sim/dex-moves').ModdedMoveDataTable = {
target.clearBoosts();
this.add('-clearboost', target);
target.addVolatile('protect');
const set = Math.floor(Math.random() * 4);
const set = this.random(4);
const newMoves = [];
let role = '';
switch (set) {
Expand Down
2 changes: 1 addition & 1 deletion sim/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class Pokemon {
set.level = this.battle.clampIntRange(set.adjustLevel || set.level || 100, 1, 9999);
this.level = set.level;
const genders: {[key: string]: GenderName} = {M: 'M', F: 'F', N: 'N'};
this.gender = genders[set.gender] || this.species.gender || (this.battle.random() * 2 < 1 ? 'M' : 'F');
this.gender = genders[set.gender] || this.species.gender || (this.battle.random(2) ? 'F' : 'M');
if (this.gender === 'N') this.gender = '';
this.happiness = typeof set.happiness === 'number' ? this.battle.clampIntRange(set.happiness, 0, 255) : 255;
this.pokeball = this.set.pokeball || 'pokeball';
Expand Down
2 changes: 1 addition & 1 deletion sim/tools/exhaustive-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class Pool {

private shuffle<T>(arr: T[]): T[] {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(this.prng.random() * (i + 1));
const j = this.prng.random(i + 1);
[arr[i], arr[j]] = [arr[j], arr[i]];
}
return arr;
Expand Down
4 changes: 2 additions & 2 deletions sim/tools/random-player-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export class RandomPlayerAI extends BattlePlayer {
// NOTE: We don't generate all possible targeting combinations.
if (request.active.length > 1) {
if ([`normal`, `any`, `adjacentFoe`].includes(m.target)) {
move += ` ${1 + Math.floor(this.prng.random() * 2)}`;
move += ` ${1 + this.prng.random(2)}`;
}
if (m.target === `adjacentAlly`) {
move += ` -${(i ^ 1) + 1}`;
}
if (m.target === `adjacentAllyOrSelf`) {
if (hasAlly) {
move += ` -${1 + Math.floor(this.prng.random() * 2)}`;
move += ` -${1 + this.prng.random(2)}`;
} else {
move += ` -${i + 1}`;
}
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 [
Math.floor(this.prng.random() * 0x10000),
Math.floor(this.prng.random() * 0x10000),
Math.floor(this.prng.random() * 0x10000),
Math.floor(this.prng.random() * 0x10000),
this.prng.random(0x10000),
this.prng.random(0x10000),
this.prng.random(0x10000),
this.prng.random(0x10000),
];
}

Expand Down

0 comments on commit f05a128

Please sign in to comment.