Discord.js 在电子游戏的地图列表中计算 2 支球队的胜率
Posted
技术标签:
【中文标题】Discord.js 在电子游戏的地图列表中计算 2 支球队的胜率【英文标题】:Discord.js calculate winrate for 2 teams on a list of maps in a video game 【发布时间】:2021-09-21 03:45:50 【问题描述】:我正在制作一个机器人,它可以计算出 2 支队伍中哪支队伍在 CSGO 的 8 张不同地图上的胜率最高。
我尝试制作一个可以计算胜率的函数,但我无法将其提取到每个团队的变量中。所以我可以在不和谐的机器人中显示它。关于如何做到这一点的任何想法?
const mapPool = ["de_ancient", "de_dust2", "de_inferno", "de_mirage", "de_nuke", "de_overpass", "de_train", "de_vertigo"];
//displayes absolute winrates. percentdisplay = perc1/(perc1+perc2)*100
function displayAbsoluteWinrates()
for(a = 0; a < mapPool.length; a++)
perc1 = team1stats[mapPool[a]];
perc2 = team2stats[mapPool[a]];
percent1 = (perc1/(perc1+perc2)*100).toFixed(0);
percent2 = (perc2/(perc1+perc2)*100).toFixed(0);
var team1map = mapPool[a];
//var div1 = document.getElementById("t1"+mapPool[a]);
//div1.innerText = percent1+"%";
//var div2 = document.getElementById("t2"+mapPool[a]);
//div2.innerText = percent2+"%";
if(percent2 > percent1)
//div1.style.backgroundColor = "red";
//div2.style.backgroundColor = "green";
else
//div1.style.backgroundColor = "green";
//div2.style.backgroundColor = "red";
if(percent2 == percent1)
//div1.style.backgroundColor = "darkorange";
//div2.style.backgroundColor = "darkorange";
```
I've rewritten some code that was meant to be for an html site into a discord bot.
Sorry if my explanation isn't that good.
【问题讨论】:
这些都与 Discord.JS 无关。你卡在哪一部分了? 【参考方案1】:代码似乎运行良好,这是我的测试方法。
如果你需要打印消息,你需要在discord.js中使用TextChannel#send
https://discordjs.guide/creating-your-bot/ 如果您在创建 discord.js 机器人时需要更多帮助。
const mapPool = ["de_ancient", "de_dust2", "de_inferno", "de_mirage", "de_nuke", "de_overpass", "de_train", "de_vertigo"];
const team1stats =
de_ancient: 50,
de_dust2: 50,
de_inferno: 10,
de_mirage: 22,
de_nuke: 44,
de_overpass: 22,
de_train: 100,
de_vertigo: 1
const team2stats =
de_ancient: 100,
de_dust2: 25,
de_inferno: 11,
de_mirage: 10,
de_nuke: 5,
de_overpass: 2,
de_train: 3,
de_vertigo: 1
for (const map of mapPool)
perc1 = team1stats[map];
perc2 = team2stats[map];
percent1 = (perc1 / (perc1 + perc2) * 100).toFixed(0);
percent2 = (perc2 / (perc1 + perc2) * 100).toFixed(0);
if (percent1 > percent2)
// Will print if Team 1 has a BETTER WIN RATE.
console.log(`Team 1: $map $percent1`);
else if (percent2 > percent1)
// Will print if Team 2 has a BETTER WIN RATE.
console.log(`Team 2: $map $percent2`);
else
// Will print if the WIN RATE is the same.
console.log(`Both Teams: $map $percent1 $percent2`);
【讨论】:
以上是关于Discord.js 在电子游戏的地图列表中计算 2 支球队的胜率的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Discord.JS v12 中查看用户正在玩的游戏
让我的 discord.js 机器人从我的计算机中的一组图像中发送一张随机图片
我如何在 discord js 中使用异步功能来制作问题游戏?