Skip to content

Commit

Permalink
sqrt-based progs
Browse files Browse the repository at this point in the history
  • Loading branch information
nicidob committed Jan 14, 2022
1 parent 8eb0d93 commit 7df4fc6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 47 deletions.
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
38 changes: 19 additions & 19 deletions src/worker/core/player/developSeason.basketball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@ import type {

// (age coefficient, age offset) for mean, than std. dev.
const ratingsFormulas: Record<Exclude<RatingKey, "hgt">, Array<number>> = {
diq: [0.0025, -0.056, -0.0, 0.0004],
dnk: [0.002, -0.0518, -0.0003, 0.0104],
drb: [0.0029, -0.0716, 0.0, 0.0],
endu: [-0.0135, 0.3619, 0.002, -0.0458],
fg: [0.0012, -0.0256, -0.0004, 0.0233],
ft: [0.0019, -0.0434, -0.0009, 0.039],
ins: [0.0007, -0.0246, 0.0004, 0.0132],
jmp: [-0.0055, 0.1173, 0.0053, -0.1313],
oiq: [-0.0003, 0.0163, -0.0001, 0.0016],
pss: [0.0021, -0.0512, -0.0, 0.0001],
reb: [0.0022, -0.0569, -0.0, 0.0002],
spd: [-0.0021, 0.0422, 0.0012, -0.0301],
stre: [-0.0001, 0.0, 0.0, 0.0],
tp: [0.0026, -0.0652, -0.0015, 0.0464],
diq: [0.008, -0.18, -0.0, 0.0012],
dnk: [0.006, -0.1601, -0.0009, 0.0317],
drb: [0.0087, -0.2156, 0.0, 0.0],
endu: [-0.0398, 1.0722, 0.0029, -0.0604],
fg: [0.0024, -0.0443, -0.0008, 0.054],
ft: [0.0052, -0.1124, -0.0012, 0.0704],
ins: [0.0027, -0.0933, -0.0006, 0.083],
jmp: [-0.0146, 0.2996, 0.0077, -0.1821],
oiq: [-0.0016, 0.0676, -0.0, 0.0012],
pss: [0.0062, -0.1502, -0.0, 0.0001],
reb: [0.0067, -0.1769, -0.0, 0.0006],
spd: [-0.0079, 0.1606, 0.0033, -0.0793],
stre: [-0.0019, 0.0375, 0.0, 0.0],
tp: [0.0079, -0.1909, -0.0025, 0.1013],
};

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

const base_coef = [-0.0044, 0.1138, 0.0004, 0.0341];
const base_coef = [-0.0148, 0.3846, -0.0001, 0.1659];

val = base_coef[0] * age + base_coef[1];
const std_base = base_coef[2] * age + base_coef[3];
const std_noise = helpers.bound(
random.realGauss(0, Math.max(0.00001, std_base)),
-0.05,
0.35,
-0.1,
0.4,
);
val += std_noise;

Expand Down Expand Up @@ -80,9 +80,9 @@ const developSeason = (

const ageChange =
ageModifier +
helpers.bound(random.realGauss(0, Math.max(0.00001, ageStd)), -0.2, 0.3);
helpers.bound(random.realGauss(0, Math.max(0.00001, ageStd)), -0.4, 0.5);
ratings[key] = limitRating(
Math.exp(Math.log(Math.max(1, ratings[key])) + baseChange + ageChange),
(Math.sqrt(Math.max(1, ratings[key])) + baseChange + ageChange) ** 2,
);
//console.log(baseChange,ageChange);
}
Expand Down
54 changes: 27 additions & 27 deletions src/worker/core/player/genRatings.basketball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,102 +29,102 @@ const genRatings = (

const pca_comp = [
[
-0.03143667, 0.13151142, -0.35923427, -0.14588372, -0.30707702,
-0.2923038, 0.35577568, 0.13378376, -0.30905554, -0.11226255, -0.36662078,
0.14404827, -0.3010302, 0.06513013, -0.38604742,
0.01143473, 0.18681705, -0.302455, -0.11453141, -0.3093686, -0.3117734,
0.39198348, 0.17170778, -0.33111817, -0.06919178, -0.31790763, 0.1837728,
-0.29564103, 0.12445679, -0.3635497,
],
[
0.28741613, 0.2948169, 0.18162839, 0.22216108, 0.04010548, -0.02320695,
0.16749835, 0.4756356, 0.08802667, 0.21357235, 0.24305432, 0.40340626,
0.05871636, 0.45862335, -0.05236033,
0.26099068, 0.32022768, 0.22354284, 0.27015418, 0.08270443, 0.06164626,
0.00622841, 0.517066, 0.07112398, 0.2629814, 0.2984516, 0.3287413,
0.06890596, 0.3749461, -0.10794741,
],
[
0.17881319, -0.36455768, 0.29882076, -0.03616037, -0.3152401, -0.26787323,
-0.27231044, -0.01128095, -0.2439317, -0.03754768, 0.50334144, 0.13699001,
-0.19139023, -0.1869137, -0.30742782,
-0.15255773, 0.38756528, -0.26229388, 0.05008439, 0.28697568, 0.2588261,
0.33136192, 0.01230466, 0.25432152, 0.04441171, -0.4698831, -0.15000868,
0.22909337, 0.23237176, 0.28194028,
],
];

const pca1 = 1.62 * hgt - 78.12 + random.realGauss(0, 13.3);
const pca2 = 0.4 * hgt - 19.41 + random.realGauss(0, 14.9);
const pca3 = -0.28 * hgt + 13.35 + random.realGauss(0, 9.0);
const pca1 = 1.72 * hgt - 83.44 + random.realGauss(0, 0.23) - 0.513;
const pca2 = 0.01 * hgt - 0.47 + random.realGauss(0, 23.1) - 14.78;
const pca3 = 0.34 * hgt - 16.39 + random.realGauss(0, 0.975) + 2.4;

const rawRatings = {
diq:
41.2 +
42.1 +
pca1 * pca_comp[0][0] +
pca2 * pca_comp[1][0] +
pca3 * pca_comp[2][0],
dnk:
46.6 +
46.5 +
pca1 * pca_comp[0][1] +
pca2 * pca_comp[1][1] +
pca3 * pca_comp[2][1],
drb:
49.1 +
50.5 +
pca1 * pca_comp[0][2] +
pca2 * pca_comp[1][2] +
pca3 * pca_comp[2][2],
endu:
32.1 +
32.5 +
pca1 * pca_comp[0][3] +
pca2 * pca_comp[1][3] +
pca3 * pca_comp[2][3],
fg:
42.3 +
42.5 +
pca1 * pca_comp[0][4] +
pca2 * pca_comp[1][4] +
pca3 * pca_comp[2][4],
ft:
42.4 +
42.5 +
pca1 * pca_comp[0][5] +
pca2 * pca_comp[1][5] +
pca3 * pca_comp[2][5],
hgt: hgt,
ins:
40.6 +
41.1 +
pca1 * pca_comp[0][7] +
pca2 * pca_comp[1][7] +
pca3 * pca_comp[2][7],
jmp:
50.1 +
51.0 +
pca1 * pca_comp[0][8] +
pca2 * pca_comp[1][8] +
pca3 * pca_comp[2][8],
oiq:
39.7 +
40.1 +
pca1 * pca_comp[0][9] +
pca2 * pca_comp[1][9] +
pca3 * pca_comp[2][9],
pss:
45.8 +
47.3 +
pca1 * pca_comp[0][10] +
pca2 * pca_comp[1][10] +
pca3 * pca_comp[2][10],
reb:
48.0 +
48.7 +
pca1 * pca_comp[0][11] +
pca2 * pca_comp[1][11] +
pca3 * pca_comp[2][11],
spd:
50.7 +
51.4 +
pca1 * pca_comp[0][12] +
pca2 * pca_comp[1][12] +
pca3 * pca_comp[2][12],
stre:
46.3 +
47.6 +
pca1 * pca_comp[0][13] +
pca2 * pca_comp[1][13] +
pca3 * pca_comp[2][13],
tp:
44.0 +
44.9 +
pca1 * pca_comp[0][14] +
pca2 * pca_comp[1][14] +
pca3 * pca_comp[2][14],
};

for (const key of helpers.keys(rawRatings)) {
rawRatings[key] = limitRating(rawRatings[key] * random.uniform(0.8, 1.2));
rawRatings[key] = limitRating(rawRatings[key] * random.uniform(0.86, 1.19));
}

const ratings = {
Expand Down

0 comments on commit 7df4fc6

Please sign in to comment.