Last active
March 14, 2022 00:50
-
-
Save chiragzq/93024ed0733c2056102457c366873593 to your computer and use it in GitHub Desktop.
Calculate optimal role selection for HLTV fantasy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let names = Array.from(document.querySelectorAll(".card-player-tag.text-ellipsis>span")).slice(0,5).map(elem => elem.innerHTML); | |
let player_buttons = Array.from(document.getElementsByClassName("assign-role-button")); | |
let role_names = []; | |
let scores = []; | |
let trigger_scores = []; | |
let BIG_MUL = 5; | |
let SMALL_MUL = 2; | |
let NUM_PLAYERS = 5; | |
let NUM_ROLES = 12; | |
let NUM_PRINT = 30; | |
function avg_points(bigRate, smallRate) { | |
return (BIG_MUL * bigRate + SMALL_MUL * smallRate - SMALL_MUL * (100-bigRate-smallRate)) / 100; | |
} | |
function calculate(ids, trigger_map) { | |
let score = 0; | |
for(let ii = 0;ii < 5;ii ++) { | |
score += trigger_map[ii][ids[ii]]; | |
} | |
return score; | |
} | |
function sleep(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(resolve, ms); | |
}) | |
} | |
(async function() { | |
for(let i = 0;i < NUM_PLAYERS;i ++) { | |
player_buttons[i].click(); | |
await sleep(10); | |
let player_scores = []; | |
let role_buttons = Array.from(document.getElementsByClassName("booster-icon-container")).slice(0,NUM_ROLES) | |
for(let j = 0;j < NUM_ROLES;j ++) { | |
role_buttons[j].click(); | |
if(i == 0) { | |
let role_name = document.getElementsByClassName("booster-description-title")[0].innerHTML; | |
role_names.push(role_name); | |
} | |
await sleep(20); | |
let big_rate = parseInt(document.getElementsByClassName("booster-trigger-rate")[0].innerText); | |
let small_rate = Number(document.getElementsByClassName("role-small-rate")[0].innerHTML.slice(0, -1)); | |
player_scores.push(avg_points(big_rate, small_rate)); | |
} | |
trigger_scores.push(player_scores); | |
player_buttons[i].click(); // close modal | |
await sleep(10); | |
} | |
console.log(trigger_scores); | |
for(let i = 0;i < NUM_ROLES;i ++) { | |
for(let j = 0;j < NUM_ROLES;j ++) { | |
for(let k = 0;k < NUM_ROLES;k ++) { | |
for(let l = 0;l < NUM_ROLES;l ++) { | |
for(let m = 0;m < NUM_ROLES;m ++) { | |
let role_ids = [i, j, k, l, m]; | |
if ((new Set(role_ids)).size != 5) continue; | |
scores.push([calculate(role_ids,trigger_scores), role_ids]) | |
} | |
} | |
} | |
} | |
} | |
scores.sort((a, b) => (b[0] - a[0])); | |
scores.slice(0, NUM_PRINT); | |
for(let i = 0;i < NUM_PRINT;i++) { | |
let print = "" + scores[i][0].toFixed(1); | |
for(let j = 0;j < NUM_PLAYERS;j ++) { | |
print += " " + names[j] + "=" + role_names[scores[i][1][j]] + ","; | |
} | |
console.log(print); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment