I’m looking at creating a more complex ranking system based on the beta-binomial method or logistic distribution, where rankings are based on success/win chance taking into account past data. My first question is if this is even possible in Roblox, since you would have to compare user data in a fairly dynamic way. My second question (and more important one) is how you could reproduce mathematics like binomials in Lua functions. I’ve never really seen relatively complex math being computed using Roblox Lua outside of calculus, so I’d be interested to see any input on this.
I was thinking about the math used in the top answer in this thread:
Otherwise anything that comes remotely close to the Chess ELO based system is good.
I found this script on GitHub which is a simplified version of what I was thinking of. The main difference is that instead of looking at all previous games and creating a success chance based on them, it compares the current score of two players and then creates a success chance based on that score. This means that uncertainty is much greater since instead of using a variance of binomial distribution it essentially uses pk = xk/nk where pk is the probability of success, xk is the number of wins and nk is the number of games played. I suppose for most purposes this would work fine.
Edit:
My bad, I didn’t read the guy’s code properly. In fact they were following logistic distribution.
I would still love to know how you could do beta-binomial or regular binomial distribution using Roblox Lua.
I’m not sure exactly what you’re looking for but the expected value of a beta function is
μ = a / (a+b)
If you’re just looking at a win/loss case this might help?
For example, what’s the odds that you’ll win this round given your previous score?
local odds = win / (win + loss)
if math.random() < odds then
print("You won!")
else
print("You lost.")
end
I have a question about this though: If I won every single game sofar, is it really 100% chance that I’ll win next one? I’m obviously missing something here..
Yeah, I did look at that. The main issue is that it’s far less comparative and dynamic in nature. If you take just the odds value from the expected value you’re missing all the data from the opponent. For example, if you take the ELO method via logistic distribution you are comparing the scores of the players, and thus all of their previous games in an abstract kind of way. This means you get a more complete picture of how a match could go (and it means there will never be a 100% certainty that any given player will win).
The other method that I was looking at, which is perhaps less utilitarian, but equally interesting, is the beta-binomial method/ empirical Bayes method. It’s what clearly requires more maths, especially to determine alpha (and only works in solitaire scenarios, although I could imagine it wouldn’t be too hard to insert an opponent once you have the base win/loss probability).
You can describe it using this formula:
𝑝̂𝑘=𝑥𝑘+𝛼̂/𝑛𝑘+𝛼̂+𝛽̂
Having said that, I don’t really understand the advantage (at least through the maths) of using that method over what you suggested, even though apparently there is one:
“extreme success rates due to highly uncertain success rate estimates for players with few games are avoided”
I guess it avoids the scenario you’ve just described where the player has a 100% success rate.