Module:Build bracket/Logic and Module:Build bracket/Logic/sandbox: Difference between pages
(Difference between pages)
imported>Pbrks allow fraction scores (e.g. ½) |
imported>Pbrks No edit summary |
||
| Line 79: | Line 79: | ||
return s | return s | ||
end | |||
-- Numeric tiebreaker inside parentheses, e.g., "2 (3)" -> 3; nil if none. | |||
local function parenTie(s) | |||
if s == nil then return nil end | |||
local str = tostring(s) | |||
local last | |||
for m in str:gmatch("%(([%d%.]+)%)") do | |||
last = tonumber(m) | |||
end | |||
return last | |||
end | end | ||
| Line 266: | Line 277: | ||
end | end | ||
if allNumeric then | if allNumeric then | ||
local | local bestMain, bestIdx, bestTB, tie = nil, nil, nil, false | ||
for _, i in ipairs(members) do | |||
local v = legNums[i][l] | |||
local raw = state.entries[j][i].score and state.entries[j][i].score[l] | |||
local tb = parenTie(raw) or 0 | |||
if bestMain == nil then | |||
bestMain, bestIdx, bestTB, tie = v, i, tb, false | |||
else | |||
if (modeLow and v < bestMain) or (not modeLow and v > bestMain) then | |||
bestMain, bestIdx, bestTB, tie = v, i, tb, false | |||
elseif v == bestMain then | |||
if (modeLow and tb < bestTB) or (not modeLow and tb > bestTB) then | |||
bestMain, bestIdx, bestTB, tie = v, i, tb, false | |||
elseif tb == bestTB then | |||
tie = true | |||
end | |||
end | |||
end | |||
end | |||
if not tie and bestIdx then | |||
wins[bestIdx] = (wins[bestIdx] or 0) + 1 | |||
end | |||
end | end | ||
end | end | ||
| Line 393: | Line 412: | ||
if not aggOnly then | if not aggOnly then | ||
-- iterate to the max leg count in the group | -- iterate to the max leg count in the group | ||
local maxL = 0 | |||
for _, i in ipairs(members) do | |||
local L = teamLegs(j, i) | |||
if L > maxL then maxL = L end | |||
end | |||
for l = 1, maxL do | |||
local allNumeric = true | |||
local bestMain, bestIdx, bestTB, tie = nil, nil, nil, false | |||
for _, i in ipairs(members) do | |||
local v = perLegNum[i] and perLegNum[i][l] | |||
if v == nil then | |||
allNumeric = false | |||
break | |||
end | |||
-- paren tiebreak (treat missing as 0 so "2 (3)" beats "2") | |||
local raw = state.entries[j][i].score and state.entries[j][i].score[l] | |||
local tb = parenTie(raw) or 0 | |||
if bestMain == nil then | |||
bestMain, bestIdx, bestTB, tie = v, i, tb, false | |||
else | |||
if (modeLow and v < bestMain) or (not modeLow and v > bestMain) then | |||
bestMain, bestIdx, bestTB, tie = v, i, tb, false | |||
elseif v == bestMain then | |||
if (modeLow and tb < bestTB) or (not modeLow and tb > bestTB) then | |||
bestMain, bestIdx, bestTB, tie = v, i, tb, false | |||
elseif tb == bestTB then | |||
tie = true | |||
end | |||
end | |||
end | |||
end | |||
if allNumeric and not tie and bestIdx then | |||
local e = state.entries[j][bestIdx] | |||
e.score.weight[l] = "bold" | |||
e.wins = (e.wins or 0) + 1 | |||
for _, i in ipairs(members) do | |||
if i ~= bestIdx then | |||
state.entries[j][i].score.weight[l] = "normal" | |||
end | |||
end | |||
else | |||
for _, i in ipairs(members) do | |||
state.entries[j][i].score.weight[l] = "normal" | |||
end | |||
end | |||
end | |||
end | end | ||