From 9bdec51059405e8e3ec5d70a4e1df0430c52939e Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Fri, 20 Mar 2026 14:00:02 +0900 Subject: [PATCH] add walkover support --- .../commons/Standings/Tiebreaker/Game.lua | 51 +++++++++++++++++++ .../Standings/Tiebreaker/Game/Count.lua | 12 +++-- .../Standings/Tiebreaker/Game/Diff.lua | 18 +++++-- .../Standings/Tiebreaker/Game/WinRate.lua | 13 +++-- .../Standings/Tiebreaker/Game/Wins.lua | 9 ++-- 5 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 lua/wikis/commons/Standings/Tiebreaker/Game.lua diff --git a/lua/wikis/commons/Standings/Tiebreaker/Game.lua b/lua/wikis/commons/Standings/Tiebreaker/Game.lua new file mode 100644 index 00000000000..d32f8b367d6 --- /dev/null +++ b/lua/wikis/commons/Standings/Tiebreaker/Game.lua @@ -0,0 +1,51 @@ +--- +-- @Liquipedia +-- page=Module:Standings/Tiebreaker/Game +-- +-- Please see https://github.com/Liquipedia/Lua-Modules to contribute +-- + +local Lua = require('Module:Lua') + +local Class = Lua.import('Module:Class') +local FnUtil = Lua.import('Module:FnUtil') + +local TiebreakerInterface = Lua.import('Module:Standings/Tiebreaker/Interface') + +---@class AbstractGameTiebreaker : StandingsTiebreaker +local AbstractGameTiebreaker = Class.new(TiebreakerInterface) + +---@protected +---@param self AbstractGameTiebreaker +---@return number +AbstractGameTiebreaker.getWalkoverCoefficient = FnUtil.memoize(function (self) + local config = self.config + if not config then + return 0 + end + return tonumber(config.walkover) or 0 +end) + +---@protected +---@return boolean +function AbstractGameTiebreaker:isWalkoverCoefficientDefined() + return self:getWalkoverCoefficient() > 0 +end + +---@protected +---@param walkover {w: integer?, l: integer?}? +---@return {w: integer, l: integer} +function AbstractGameTiebreaker:calculateWalkoverValues(walkover) + if not self:isWalkoverCoefficientDefined() or not walkover then + return {w = 0, l = 0} + end + + local walkoverCoefficient = self:getWalkoverCoefficient() + + return { + w = (walkover.w or 0) * walkoverCoefficient, + l = (walkover.l or 0) * walkoverCoefficient + } +end + +return AbstractGameTiebreaker diff --git a/lua/wikis/commons/Standings/Tiebreaker/Game/Count.lua b/lua/wikis/commons/Standings/Tiebreaker/Game/Count.lua index f313c615bea..f9e7ae9e69b 100644 --- a/lua/wikis/commons/Standings/Tiebreaker/Game/Count.lua +++ b/lua/wikis/commons/Standings/Tiebreaker/Game/Count.lua @@ -9,18 +9,22 @@ local Lua = require('Module:Lua') local Class = Lua.import('Module:Class') +local AbstractGameTiebreaker = Lua.import('Module:Standings/Tiebreaker/Game') local TiebreakerGameUtil = Lua.import('Module:Standings/Tiebreaker/Game/Util') -local TiebreakerInterface = Lua.import('Module:Standings/Tiebreaker/Interface') ----@class TiebreakerGameCount : StandingsTiebreaker -local TiebreakerGameCount = Class.new(TiebreakerInterface) +---@class TiebreakerGameCount : AbstractGameTiebreaker +local TiebreakerGameCount = Class.new(AbstractGameTiebreaker) ---@param state TiebreakerOpponent[] ---@param opponent TiebreakerOpponent ---@return integer function TiebreakerGameCount:valueOf(state, opponent) local games = TiebreakerGameUtil.getGames(opponent) - return games.games + if not games.walkover or not self:isWalkoverCoefficientDefined() then + return games.games + end + local walkoverGames = self:calculateWalkoverValues(games.walkover) + return games.games + (self:getWalkoverCoefficient() * (walkoverGames.w + walkoverGames.l)) end ---@return string diff --git a/lua/wikis/commons/Standings/Tiebreaker/Game/Diff.lua b/lua/wikis/commons/Standings/Tiebreaker/Game/Diff.lua index cd24b516de8..a1cda77139c 100644 --- a/lua/wikis/commons/Standings/Tiebreaker/Game/Diff.lua +++ b/lua/wikis/commons/Standings/Tiebreaker/Game/Diff.lua @@ -9,18 +9,22 @@ local Lua = require('Module:Lua') local Class = Lua.import('Module:Class') +local AbstractGameTiebreaker = Lua.import('Module:Standings/Tiebreaker/Game') local TiebreakerGameUtil = Lua.import('Module:Standings/Tiebreaker/Game/Util') -local TiebreakerInterface = Lua.import('Module:Standings/Tiebreaker/Interface') ----@class TiebreakerGameDiff : StandingsTiebreaker -local TiebreakerGameDiff = Class.new(TiebreakerInterface) +---@class TiebreakerGameDiff : AbstractGameTiebreaker +local TiebreakerGameDiff = Class.new(AbstractGameTiebreaker) ---@param state TiebreakerOpponent[] ---@param opponent TiebreakerOpponent ---@return integer function TiebreakerGameDiff:valueOf(state, opponent) local games = TiebreakerGameUtil.getGames(opponent) - return games.w - games.l + if not games.walkover or not self:isWalkoverCoefficientDefined() then + return games.w - games.l + end + local walkoverGames = self:calculateWalkoverValues(games.walkover) + return (games.w + walkoverGames.w) - (games.l + walkoverGames.l) end ---@return string @@ -33,7 +37,11 @@ end ---@return string function TiebreakerGameDiff:display(state, opponent) local games = TiebreakerGameUtil.getGames(opponent) - return games.w .. ' - ' .. games.l + if not games.walkover or not self:isWalkoverCoefficientDefined() then + return games.w .. ' - ' .. games.l + end + local walkoverGames = self:calculateWalkoverValues(games.walkover) + return (games.w + walkoverGames.w) .. ' - ' .. (games.l + walkoverGames.l) end return TiebreakerGameDiff diff --git a/lua/wikis/commons/Standings/Tiebreaker/Game/WinRate.lua b/lua/wikis/commons/Standings/Tiebreaker/Game/WinRate.lua index 7857f82855c..b506f9bdbce 100644 --- a/lua/wikis/commons/Standings/Tiebreaker/Game/WinRate.lua +++ b/lua/wikis/commons/Standings/Tiebreaker/Game/WinRate.lua @@ -10,18 +10,23 @@ local Lua = require('Module:Lua') local Class = Lua.import('Module:Class') local MathUtil = Lua.import('Module:MathUtil') +local AbstractGameTiebreaker = Lua.import('Module:Standings/Tiebreaker/Game') local TiebreakerGameUtil = Lua.import('Module:Standings/Tiebreaker/Game/Util') -local TiebreakerInterface = Lua.import('Module:Standings/Tiebreaker/Interface') ----@class TiebreakerGameWinRate : StandingsTiebreaker -local TiebreakerGameWinRate = Class.new(TiebreakerInterface) +---@class TiebreakerGameWinRate : AbstractGameTiebreaker +local TiebreakerGameWinRate = Class.new(AbstractGameTiebreaker) ---@param state TiebreakerOpponent[] ---@param opponent TiebreakerOpponent ---@return integer function TiebreakerGameWinRate:valueOf(state, opponent) local games = TiebreakerGameUtil.getGames(opponent) - return games.games == 0 and 0.5 or (games.w / games.games) + if not games.walkover or not self:isWalkoverCoefficientDefined() then + return games.games == 0 and 0.5 or (games.w / games.games) + end + local walkoverGames = self:calculateWalkoverValues(games.walkover) + local totalGames = games.games + walkoverGames.w + walkoverGames.l + return (games.w + walkoverGames.w) / totalGames end ---@return string diff --git a/lua/wikis/commons/Standings/Tiebreaker/Game/Wins.lua b/lua/wikis/commons/Standings/Tiebreaker/Game/Wins.lua index 779aafac3c9..dcc19c3c1ad 100644 --- a/lua/wikis/commons/Standings/Tiebreaker/Game/Wins.lua +++ b/lua/wikis/commons/Standings/Tiebreaker/Game/Wins.lua @@ -9,18 +9,19 @@ local Lua = require('Module:Lua') local Class = Lua.import('Module:Class') +local AbstractGameTiebreaker = Lua.import('Module:Standings/Tiebreaker/Game') local TiebreakerGameUtil = Lua.import('Module:Standings/Tiebreaker/Game/Util') -local TiebreakerInterface = Lua.import('Module:Standings/Tiebreaker/Interface') ----@class TiebreakerGameWins : StandingsTiebreaker -local TiebreakerGameWins = Class.new(TiebreakerInterface) +---@class TiebreakerGameWins : AbstractGameTiebreaker +local TiebreakerGameWins = Class.new(AbstractGameTiebreaker) ---@param state TiebreakerOpponent[] ---@param opponent TiebreakerOpponent ---@return integer function TiebreakerGameWins:valueOf(state, opponent) local games = TiebreakerGameUtil.getGames(opponent) - return games.w + local walkoverGames = self:calculateWalkoverValues(games.walkover) + return games.w + walkoverGames.w end ---@return string