Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(match2): Support the use of playall instead of bestof #5148

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 13 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
18 changes: 17 additions & 1 deletion components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ function MatchGroupInputUtil.matchIsFinished(match, opponents)
return true
end

local playall = tonumber(match.playall) or 0
if playall > 0 then
return MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
end

local bestof = match.bestof
if not bestof then
return false
Expand Down Expand Up @@ -891,6 +896,15 @@ function MatchGroupInputUtil.majorityHasBeenWon(bestof, opponents)
return false
end

-- Check if all games/rounds have been played
---@param playall integer
---@param opponents {score: integer?}[]
---@return boolean
function MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
local scoreSum = Array.reduce(opponents, function(sum, opponent) return sum + (opponent.score or 0) end, 0)
return scoreSum >= playall
end
Comment on lines +901 to +904
Copy link
Collaborator

@Rathoz Rathoz Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
local scoreSum = Array.reduce(opponents, function(sum, opponent) return sum + (opponent.score or 0) end, 0)
return scoreSum >= playall
end
function MatchGroupInputUtil.allHasBeenPlayed(games)
return Array.all(games, function(game) return game.finished end)
end

Wouldn't this do it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you are right in this case then, shouldn't we just refactor playall to be a true/false variable, since the number of games for bestof is calculated by number of maps that are in the input?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not the case on all wikis fwiw

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I mean like the use of PlayAll is currently only calculated if PlayAll is non-zero? And thus far this has no representation, for example, in making Ticker use {{Abbr/PaX}} instead of {{Abbr/BoX}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the true/false version personally

Copy link
Collaborator Author

@fregerson fregerson Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried it that way instead in the below commit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait a second, breaks when no maps are provided :/


---@param bestOfInput string|integer?
---@param maps table[]
---@return integer?
Expand Down Expand Up @@ -1141,6 +1155,8 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)

match.stream = Streams.processStreams(match)
match.extradata = Parser.getExtraData and Parser.getExtraData(match, games, opponents) or {}
match.extradata = Table.merge({playall = tonumber(match.playall)}, match.extradata)
match.bestof = tonumber(match.playall) --For display in existing Bestof?
fregerson marked this conversation as resolved.
Show resolved Hide resolved

match.games = games
match.opponents = opponents
Expand Down Expand Up @@ -1383,4 +1399,4 @@ function MatchGroupInputUtil.calculatePlacementOfOpponents(opponents)
end


return MatchGroupInputUtil
return MatchGroupInputUtil
fregerson marked this conversation as resolved.
Show resolved Hide resolved
fregerson marked this conversation as resolved.
Show resolved Hide resolved
Loading