Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative progs with smaller changes #405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/worker/core/draft/genPlayersWithoutSaving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const genPlayersWithoutSaving = async (
}

// Small chance of making top 4 players (in 70 player draft) special - on average, one per draft class
if (existingPlayers.length === 0) {
if (!isSport("basketball") && existingPlayers.length === 0) {
const numSpecialPlayerChances = Math.round((4 / 70) * numPlayers);

for (let i = 0; i < numSpecialPlayerChances; i++) {
Expand Down
230 changes: 31 additions & 199 deletions src/worker/core/player/developSeason.basketball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,200 +5,34 @@ import type {
RatingKey,
} from "../../../common/types.basketball";

type RatingFormula = {
ageModifier: (age: number) => number;
changeLimits: (age: number) => [number, number];
};

const shootingFormula: RatingFormula = {
ageModifier: (age: number) => {
// Reverse most of the age-related decline in calcBaseChange
if (age <= 27) {
return 0;
}

if (age <= 29) {
return 0.5;
}

if (age <= 31) {
return 1.5;
}

return 2;
},
changeLimits: () => [-3, 13],
};
const iqFormula: RatingFormula = {
ageModifier: (age: number) => {
if (age <= 21) {
return 4;
}

if (age <= 23) {
return 3;
}

// Reverse most of the age-related decline in calcBaseChange
if (age <= 27) {
return 0;
}

if (age <= 29) {
return 0.5;
}

if (age <= 31) {
return 1.5;
}

return 2;
},
changeLimits: age => {
if (age >= 24) {
return [-3, 9];
}

// For 19: [-3, 32]
// For 23: [-3, 12]
return [-3, 7 + 5 * (24 - age)];
},
};
const ratingsFormulas: Record<Exclude<RatingKey, "hgt">, RatingFormula> = {
stre: {
ageModifier: () => 0,
changeLimits: () => [-Infinity, Infinity],
},
spd: {
ageModifier: (age: number) => {
if (age <= 27) {
return 0;
}

if (age <= 30) {
return -2;
}

if (age <= 35) {
return -3;
}

if (age <= 40) {
return -4;
}

return -8;
},
changeLimits: () => [-12, 2],
},
jmp: {
ageModifier: (age: number) => {
if (age <= 26) {
return 0;
}

if (age <= 30) {
return -3;
}

if (age <= 35) {
return -4;
}

if (age <= 40) {
return -5;
}

return -10;
},
changeLimits: () => [-12, 2],
},
endu: {
ageModifier: (age: number) => {
if (age <= 23) {
return random.uniform(0, 9);
}

if (age <= 30) {
return 0;
}

if (age <= 35) {
return -2;
}

if (age <= 40) {
return -4;
}

return -8;
},
changeLimits: () => [-11, 19],
},
dnk: {
ageModifier: (age: number) => {
// Like shootingForumla, except for old players
if (age <= 27) {
return 0;
}

return 0.5;
},
changeLimits: () => [-3, 13],
},
ins: shootingFormula,
ft: shootingFormula,
fg: shootingFormula,
tp: shootingFormula,
oiq: iqFormula,
diq: iqFormula,
drb: {
ageModifier: shootingFormula.ageModifier,
changeLimits: () => [-2, 5],
},
pss: {
ageModifier: shootingFormula.ageModifier,
changeLimits: () => [-2, 5],
},
reb: {
ageModifier: shootingFormula.ageModifier,
changeLimits: () => [-2, 5],
},
// (age coefficient, age offset) for mean, than std. dev.
const ratingsFormulas: Record<Exclude<RatingKey, "hgt">, Array<number>> = {
diq: [-0.1, 2.841, -0.95],
dnk: [-0.052, 1.781, 1.205],
drb: [0.097, -3.06, -0.014],
endu: [-0.52, 13.842, 2.301],
fg: [0.015, 0.07, 0.544],
ft: [0.155, -3.891, -0.071],
ins: [-0.032, 0.924, 0.756],
jmp: [-0.247, 5.446, 1.486],
oiq: [0.076, -2.039, 0.406],
pss: [0.157, -4.602, 0.288],
reb: [0.042, -0.964, -0.098],
spd: [-0.057, 0.44, 0.323],
stre: [-0.099, 2.675, 0.231],
tp: [0.138, -3.909, 0.68],
};

const calcBaseChange = (age: number, coachingRank: number): number => {
let val: number;

if (age <= 21) {
val = 2;
} else if (age <= 25) {
val = 1;
} else if (age <= 27) {
val = 0;
} else if (age <= 29) {
val = -1;
} else if (age <= 31) {
val = -2;
} else if (age <= 34) {
val = -3;
} else if (age <= 40) {
val = -4;
} else if (age <= 43) {
val = -5;
} else {
val = -6;
}
const base_coef = [-0.327, 8.0, 4.202];

// Noise
if (age <= 23) {
val += helpers.bound(random.realGauss(0, 5), -4, 20);
} else if (age <= 25) {
val += helpers.bound(random.realGauss(0, 5), -4, 10);
} else {
val += helpers.bound(random.realGauss(0, 3), -2, 4);
}
val = base_coef[0] * age + base_coef[1];
const std_base = base_coef[2];
const std_noise = helpers.bound(random.realGauss() * std_base, -1, 4);
val += std_noise;

// Modulate by coaching. g.get("numActiveTeams") doesn't exist when upgrading DB, but that doesn't matter
if (g.hasOwnProperty("numActiveTeams")) {
const numActiveTeams = g.get("numActiveTeams");
if (numActiveTeams > 1) {
Expand Down Expand Up @@ -230,21 +64,19 @@ const developSeason = (
ratings.hgt += 1;
}
}
const age_bounds = helpers.bound(age, 19, 50);

const baseChange = calcBaseChange(age, coachingRank);
const baseChange = calcBaseChange(age_bounds, coachingRank);

for (const key of helpers.keys(ratingsFormulas)) {
const ageModifier = ratingsFormulas[key].ageModifier(age);
const changeLimits = ratingsFormulas[key].changeLimits(age);

ratings[key] = limitRating(
ratings[key] +
helpers.bound(
(baseChange + ageModifier) * random.uniform(0.4, 1.4),
changeLimits[0],
changeLimits[1],
),
);
const ageModifier =
ratingsFormulas[key][0] * age_bounds + ratingsFormulas[key][1];
const ageStd = ratingsFormulas[key][2];

const ageChange =
ageModifier + helpers.bound(random.realGauss() * ageStd, -3, 5);
ratings[key] = limitRating(ratings[key] + baseChange + ageChange);
//console.log(baseChange,ageChange);
}
};

Expand Down
38 changes: 19 additions & 19 deletions src/worker/core/player/genRatings.basketball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,28 @@ const genRatings = (

// Tall players are less talented, and all tend towards dumb and can't shoot because they are rookies
const rawRatings = {
stre: 37,
spd: 40,
jmp: 40,
endu: 17,
ins: 27,
dnk: 27,
ft: 32,
fg: 32,
tp: 32,
oiq: 22,
diq: 22,
drb: 37,
pss: 37,
reb: 37,
diq: 39,
dnk: 39,
drb: 40,
endu: 23,
fg: 34,
ft: 36,
ins: 38,
jmp: 35,
oiq: 38,
pss: 39,
reb: 45,
spd: 37,
stre: 46,
tp: 40,
};

// For correlation across ratings, to ensure some awesome players, but athleticism and skill are independent to
// ensure there are some who are elite in one but not the other
const factorAthleticism = helpers.bound(random.realGauss(1, 0.2), 0.2, 1.2);
const factorShooting = helpers.bound(random.realGauss(1, 0.2), 0.2, 1.2);
const factorSkill = helpers.bound(random.realGauss(1, 0.2), 0.2, 1.2);
const factorIns = helpers.bound(random.realGauss(1, 0.2), 0.2, 1.2);
const factorAthleticism = random.realGauss(1, 0.01);
const factorShooting = random.realGauss(1, 0.11);
const factorSkill = random.realGauss(1, 0.08);
const factorIns = random.realGauss(1, 0.03);
const athleticismRatings = ["stre", "spd", "jmp", "endu", "dnk"];
const shootingRatings = ["ft", "fg", "tp"];
const skillRatings = ["oiq", "diq", "drb", "pss", "reb"]; // ins purposely left out
Expand All @@ -145,7 +145,7 @@ const genRatings = (
}

rawRatings[key] = limitRating(
factor * typeFactor * random.realGauss(rawRatings[key], 3),
factor * typeFactor * random.realGauss(rawRatings[key], 0.8),
);
}

Expand Down
32 changes: 16 additions & 16 deletions src/worker/core/player/ovr.basketball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import type { PlayerRatings } from "../../../common/types.basketball";
const ovr = (ratings: PlayerRatings): number => {
// See analysis/player-ovr-basketball
const r =
0.159 * (ratings.hgt - 47.5) +
0.0777 * (ratings.stre - 50.2) +
0.123 * (ratings.spd - 50.8) +
0.051 * (ratings.jmp - 48.7) +
0.0632 * (ratings.endu - 39.9) +
0.0126 * (ratings.ins - 42.4) +
0.0286 * (ratings.dnk - 49.5) +
0.0202 * (ratings.ft - 47.0) +
0.0726 * (ratings.tp - 47.1) +
0.133 * (ratings.oiq - 46.8) +
0.159 * (ratings.diq - 46.7) +
0.059 * (ratings.drb - 54.8) +
0.062 * (ratings.pss - 51.3) +
0.01 * (ratings.fg - 47.0) +
0.01 * (ratings.reb - 51.4) +
48.5;
0.0935 * ratings.diq +
0.042 * ratings.dnk +
0.0969 * ratings.drb +
0.00725 * ratings.endu +
-0.00948 * ratings.fg +
0.0488 * ratings.ft +
0.225 * ratings.hgt +
-0.0143 * ratings.ins +
0.0502 * ratings.jmp +
0.0974 * ratings.oiq +
0.0656 * ratings.pss +
0.0533 * ratings.reb +
0.156 * ratings.spd +
0.0962 * ratings.stre +
0.105 * ratings.tp +
-6.4;

// Fudge factor to keep ovr ratings the same as they used to be (back before 2018 ratings rescaling)
// +8 at 68
Expand Down