Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lua/wikis/commons/Standings/Tiebreaker/Game.lua
Original file line number Diff line number Diff line change
@@ -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
12 changes: 8 additions & 4 deletions lua/wikis/commons/Standings/Tiebreaker/Game/Count.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions lua/wikis/commons/Standings/Tiebreaker/Game/Diff.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
13 changes: 9 additions & 4 deletions lua/wikis/commons/Standings/Tiebreaker/Game/WinRate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions lua/wikis/commons/Standings/Tiebreaker/Game/Wins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading