-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
64 lines (50 loc) · 1.33 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
local moba = require "moba"
local math = require "math"
-- 阈值
local delta_rank = 2
local delta_score = 10
local delta_role = 4
-- 各路的权值
local weight_top = 0.3
local weight_bot = 0.2
local weight_mid = 0.2
local weight_jg = 0.2
local weight_sup = 0.1
-- 队伍 g 的加权平均 score 值
function score(g)
return moba.score(g, weight_top, weight_bot, weight_mid, weight_jg, weight_sup)
end
-- 队伍 g1 相较于 g2 的 ELO 值
function elo(g1, g2)
return 1 / (1 + math.pow(10, (score(g2)-score(g1)) / 400))
end
-- 示例匹配规则
function match(g1, g2)
-- 若段位差超过 delta_rank 则匹配失败
local rank_min1, rank_max1 = moba.rank(g1)
local rank_min2, rank_max2 = moba.rank(g2)
if ((rank_max1 - rank_min2) > delta_rank) or ((rank_max2 - rank_min1) > delta_rank) then
return false
end
-- 若路线覆盖没有达到 delta_role 则匹配失败
local role1 = moba.role(g1)
local role2 = moba.role(g2)
if (bitcount5(role1 | role2) < delta_role) then
return false
end
-- 若 score 之差超过 delta_score 则匹配失败
local s1 = score(g1)
local s2 = score(g2)
return math.abs(s1 - s2) < delta_score
end
-- 统计 x 的低 5 位为 1 的个数
function bitcount5(x)
local c = 0
for i = 0, 5, 1 do
if (x & 1) == 1 then
c = c + 1
end
x = x >> 1
end
return c
end