<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="uz">
	<id>https://ziyosfera.uz/index.php?action=history&amp;feed=atom&amp;title=Modul%3ATeamBracket</id>
	<title>Modul:TeamBracket - Oʻzgarishlar tarixi</title>
	<link rel="self" type="application/atom+xml" href="https://ziyosfera.uz/index.php?action=history&amp;feed=atom&amp;title=Modul%3ATeamBracket"/>
	<link rel="alternate" type="text/html" href="https://ziyosfera.uz/index.php?title=Modul:TeamBracket&amp;action=history"/>
	<updated>2026-11-18T18:05:52Z</updated>
	<subtitle>Ziyosferadagi mazkur sahifaning oʻzgarishlar tarixi</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://ziyosfera.uz/index.php?title=Modul:TeamBracket&amp;diff=110605&amp;oldid=prev</id>
		<title>Programmer: Oʻzbekcha Vikipediyadan import qilindi.</title>
		<link rel="alternate" type="text/html" href="https://ziyosfera.uz/index.php?title=Modul:TeamBracket&amp;diff=110605&amp;oldid=prev"/>
		<updated>2026-08-06T12:12:28Z</updated>

		<summary type="html">&lt;p&gt;Oʻzbekcha Vikipediyadan import qilindi.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Yangi sahifa&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- This module will implement {{TeamBracket}}&lt;br /&gt;
--&lt;br /&gt;
 &lt;br /&gt;
local p = {}&lt;br /&gt;
local args&lt;br /&gt;
local rounds&lt;br /&gt;
local padding&lt;br /&gt;
&lt;br /&gt;
local function getArgs(frame)&lt;br /&gt;
	local parent = frame:getParent();&lt;br /&gt;
	local args = parent.args;&lt;br /&gt;
	for k,v in pairs(frame.args) do &lt;br /&gt;
		args[k] = v&lt;br /&gt;
	end&lt;br /&gt;
	return args;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function getSeeds()&lt;br /&gt;
	local seeds = {1, 2}&lt;br /&gt;
	local count = 2&lt;br /&gt;
	local before = false&lt;br /&gt;
	for r = 2, rounds do&lt;br /&gt;
		local max = math.pow(2, r)&lt;br /&gt;
		for i = 1, count do&lt;br /&gt;
			local pos = i * 2&lt;br /&gt;
			if before then pos = pos - 1 end&lt;br /&gt;
			table.insert(seeds, pos, max - seeds[i * 2 - 1] + 1)&lt;br /&gt;
			before = not before&lt;br /&gt;
		end&lt;br /&gt;
		count = count * 2&lt;br /&gt;
	end&lt;br /&gt;
	return seeds&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function addTableRow(tbl)&lt;br /&gt;
	return tbl:tag(&amp;#039;tr&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function addBlank(row, width)&lt;br /&gt;
	local cell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-width&amp;#039;, &amp;#039;0&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-style&amp;#039;, &amp;#039;solid&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-color&amp;#039;, &amp;#039;black&amp;#039;)&lt;br /&gt;
	if width then&lt;br /&gt;
		cell:css(&amp;#039;width&amp;#039;, width)&lt;br /&gt;
	end&lt;br /&gt;
	return cell&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function addPath(rows, index, round, top, left)&lt;br /&gt;
	local prop = top and &amp;#039;border-bottom-width&amp;#039; or &amp;#039;border-top-width&amp;#039;&lt;br /&gt;
	if left and round == 1 then&lt;br /&gt;
		addBlank(rows[index]):css(&amp;#039;height&amp;#039;, &amp;#039;7px&amp;#039;)&lt;br /&gt;
		addBlank(rows[index + 1]):css(&amp;#039;height&amp;#039;, &amp;#039;7px&amp;#039;)&lt;br /&gt;
		return nil&lt;br /&gt;
	else&lt;br /&gt;
		local cell = addBlank(rows[index]):attr(&amp;#039;rowspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
		if left or round &amp;lt; rounds and not left then&lt;br /&gt;
			cell:css(prop, &amp;#039;2px&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		return cell&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function getWidth(param, default)&lt;br /&gt;
	local arg = args[param .. &amp;#039;-width&amp;#039;]&lt;br /&gt;
	if not arg or string.len(arg) == 0 then&lt;br /&gt;
		arg = default&lt;br /&gt;
	end&lt;br /&gt;
	if tonumber(arg) ~= nil then&lt;br /&gt;
		arg = arg .. &amp;#039;px&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	return arg&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function getTeamArg(round, type, team)&lt;br /&gt;
	return args[getTeamArgName(round, type, team)]&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function getTeamArgName(round, type, team)&lt;br /&gt;
	return string.format(&amp;#039;RD%d-%s&amp;#039; .. padding, round, type, team)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function getRoundName(round)&lt;br /&gt;
	local name = args[&amp;#039;RD&amp;#039; .. round]&lt;br /&gt;
	if name and string.len(name) &amp;gt; 0 then&lt;br /&gt;
		return name&lt;br /&gt;
	end&lt;br /&gt;
	local roundFromLast = rounds - round + 1&lt;br /&gt;
	if roundFromLast == 1 then&lt;br /&gt;
		return &amp;quot;Finals&amp;quot;&lt;br /&gt;
	elseif roundFromLast == 2 then&lt;br /&gt;
		return &amp;quot;Semifinals&amp;quot;&lt;br /&gt;
	elseif roundFromLast == 3 then&lt;br /&gt;
		return &amp;quot;Quarterfinals&amp;quot;&lt;br /&gt;
	else&lt;br /&gt;
		return &amp;quot;Round of &amp;quot; .. math.pow(2, roundFromLast)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
function renderTeam(row, round, team)&lt;br /&gt;
	local seedArg = getTeamArg(round, &amp;#039;seed&amp;#039;, team)&lt;br /&gt;
	-- seed value for the paired team&lt;br /&gt;
	local pairSeedArg = getTeamArg(round, &amp;#039;seed&amp;#039;,&lt;br /&gt;
		team % 2 == 0 and team - 1 or team + 1)&lt;br /&gt;
	-- show seed if seed is defined for either or both&lt;br /&gt;
	local showSeed = seedArg and string.len(seedArg) &amp;gt; 0&lt;br /&gt;
		or pairSeedArg and string.len(pairSeedArg) &amp;gt; 0&lt;br /&gt;
	if showSeed then&lt;br /&gt;
		row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
			:attr(&amp;#039;rowspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;background-color&amp;#039;, &amp;#039;#f2f2f2&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;border&amp;#039;, &amp;#039;1px solid #aaa&amp;#039;)&lt;br /&gt;
			:wikitext(seedArg)&lt;br /&gt;
			:newline()&lt;br /&gt;
	end&lt;br /&gt;
	local teamArg = getTeamArg(round, &amp;#039;team&amp;#039;, team)&lt;br /&gt;
	if not teamArg or string.len(teamArg) == 0 then&lt;br /&gt;
		teamArg = &amp;#039;&amp;amp;nbsp;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	local teamCell = row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;rowspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;background-color&amp;#039;, &amp;#039;#f9f9f9&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border&amp;#039;, &amp;#039;1px solid #aaa&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;padding&amp;#039;, &amp;#039;0 2px&amp;#039;)&lt;br /&gt;
		:wikitext(teamArg)&lt;br /&gt;
		:newline()&lt;br /&gt;
	if not showSeed then&lt;br /&gt;
		teamCell:attr(&amp;#039;colspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	row:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
		:attr(&amp;#039;rowspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border&amp;#039;, &amp;#039;1px solid #aaa&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;background-color&amp;#039;, &amp;#039;#f9f9f9&amp;#039;)&lt;br /&gt;
		:wikitext(getTeamArg(round, &amp;#039;score&amp;#039;, team))&lt;br /&gt;
		:newline()&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function renderRound(rows, count, r)	&lt;br /&gt;
	local teams = math.pow(2, rounds - r + 1)&lt;br /&gt;
	local step = count / teams&lt;br /&gt;
	local top = true&lt;br /&gt;
	local open = false&lt;br /&gt;
	local team = 1&lt;br /&gt;
	for i = 1, count, step do&lt;br /&gt;
		local offset, height, blank&lt;br /&gt;
		-- leave room for groups for teams other than first and last&lt;br /&gt;
		if team == 1 or team == teams then&lt;br /&gt;
			offset = top and i or i + 2&lt;br /&gt;
			height = step - 2&lt;br /&gt;
		else&lt;br /&gt;
			offset = top and i + 1 or i + 2&lt;br /&gt;
			height = step - 3&lt;br /&gt;
		end&lt;br /&gt;
		if height &amp;gt; 0 then&lt;br /&gt;
			blank = addBlank(rows[offset])&lt;br /&gt;
				:attr(&amp;#039;colspan&amp;#039;, &amp;#039;5&amp;#039;)&lt;br /&gt;
				:attr(&amp;#039;rowspan&amp;#039;, height)&lt;br /&gt;
		end&lt;br /&gt;
		-- add bracket&lt;br /&gt;
		local j = top and i + step - 2 or i&lt;br /&gt;
		addPath(rows, j, r, top, true)&lt;br /&gt;
		renderTeam(rows[j], r, team)&lt;br /&gt;
		local right = addPath(rows, j, r, top, false)&lt;br /&gt;
		if not top then open = not open end&lt;br /&gt;
		if open and r &amp;lt; rounds then&lt;br /&gt;
			if blank then blank:css(&amp;#039;border-right-width&amp;#039;, &amp;#039;2px&amp;#039;) end&lt;br /&gt;
			right:css(&amp;#039;border-right-width&amp;#039;, &amp;#039;2px&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
		team = team + 1&lt;br /&gt;
		top = not top&lt;br /&gt;
	end&lt;br /&gt;
end	&lt;br /&gt;
&lt;br /&gt;
function renderGroups(rows, count, round)&lt;br /&gt;
	local roundFromLast = rounds - round + 1&lt;br /&gt;
	local groups = math.pow(2, roundFromLast - 2)&lt;br /&gt;
	local step = count / groups&lt;br /&gt;
	local group = 1&lt;br /&gt;
	for i = step / 2, count, step do&lt;br /&gt;
		local name = &amp;#039;RD&amp;#039; .. round .. &amp;#039;-group&amp;#039; .. group&lt;br /&gt;
		addBlank(rows[i]):css(&amp;#039;height&amp;#039;, &amp;#039;7px&amp;#039;)&lt;br /&gt;
		addBlank(rows[i + 1]):css(&amp;#039;height&amp;#039;, &amp;#039;7px&amp;#039;)&lt;br /&gt;
		addBlank(rows[i])&lt;br /&gt;
			:attr(&amp;#039;rowspan&amp;#039;, &amp;#039;2&amp;#039;)&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, 5 * round - 1)&lt;br /&gt;
			:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;border-right-width&amp;#039;, &amp;#039;2px&amp;#039;)&lt;br /&gt;
			:wikitext(args[name])&lt;br /&gt;
			:newline()&lt;br /&gt;
		group = group + 1&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function renderTree(tbl)&lt;br /&gt;
	-- create 3 rows for every team&lt;br /&gt;
	local count = math.pow(2, rounds) * 3&lt;br /&gt;
	local rows = {}&lt;br /&gt;
	for i = 1, count do&lt;br /&gt;
		rows[i] = addTableRow(tbl)&lt;br /&gt;
	end&lt;br /&gt;
	-- fill rows with groups&lt;br /&gt;
	for r = 1, rounds - 1 do&lt;br /&gt;
		renderGroups(rows, count, r)&lt;br /&gt;
	end&lt;br /&gt;
	-- fill rows with bracket&lt;br /&gt;
	for r = 1, rounds do&lt;br /&gt;
		renderRound(rows, count, r)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function renderHeading(tbl)&lt;br /&gt;
	local titleRow = addTableRow(tbl)&lt;br /&gt;
	local widthRow = addTableRow(tbl)&lt;br /&gt;
	for r = 1, rounds do&lt;br /&gt;
		addBlank(titleRow)&lt;br /&gt;
		addBlank(widthRow, r &amp;gt; 1 and &amp;#039;5px&amp;#039; or nil)&lt;br /&gt;
		titleRow:tag(&amp;#039;td&amp;#039;)&lt;br /&gt;
			:attr(&amp;#039;colspan&amp;#039;, &amp;#039;3&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;text-align&amp;#039;, &amp;#039;center&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;border&amp;#039;, &amp;#039;1px solid #aaa&amp;#039;)&lt;br /&gt;
			:css(&amp;#039;background-color&amp;#039;, &amp;#039;#f2f2f2&amp;#039;)&lt;br /&gt;
			:wikitext(getRoundName(r))&lt;br /&gt;
			:newline()&lt;br /&gt;
		addBlank(widthRow, getWidth(&amp;#039;seed&amp;#039;, &amp;#039;25px&amp;#039;)):wikitext(&amp;#039;&amp;amp;nbsp;&amp;#039;)&lt;br /&gt;
		addBlank(widthRow, getWidth(&amp;#039;team&amp;#039;, &amp;#039;150px&amp;#039;)):wikitext(&amp;#039;&amp;amp;nbsp;&amp;#039;)&lt;br /&gt;
		addBlank(widthRow, getWidth(&amp;#039;score&amp;#039;, &amp;#039;25px&amp;#039;)):wikitext(&amp;#039;&amp;amp;nbsp;&amp;#039;)&lt;br /&gt;
		addBlank(titleRow)&lt;br /&gt;
		addBlank(widthRow, r &amp;lt; rounds and &amp;#039;5px&amp;#039; or nil)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.teamBracket(frame)&lt;br /&gt;
	args = getArgs(frame)&lt;br /&gt;
	rounds = tonumber(args.rounds) or 2&lt;br /&gt;
	local teams = math.pow(2, rounds)&lt;br /&gt;
	padding = &amp;#039;%0&amp;#039; .. (teams &amp;lt; 10 and 1 or 2) .. &amp;#039;d&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	-- set default seeds for round 1&lt;br /&gt;
	local seeds = getSeeds()&lt;br /&gt;
	local argname;&lt;br /&gt;
	for i = 1, table.getn(seeds) do&lt;br /&gt;
		argname = getTeamArgName(1, &amp;#039;seed&amp;#039;, i)&lt;br /&gt;
		if not args[argname] then&lt;br /&gt;
			args[argname] = seeds[i]&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local tbl = mw.html.create(&amp;#039;table&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-style&amp;#039;, &amp;#039;none&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;font-size&amp;#039;, &amp;#039;90%&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;margin&amp;#039;, &amp;#039;1em 2em 1em 1em&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-collapse&amp;#039;, &amp;#039;separate&amp;#039;)&lt;br /&gt;
		:css(&amp;#039;border-spacing&amp;#039;, &amp;#039;0&amp;#039;)&lt;br /&gt;
 &lt;br /&gt;
	renderHeading(tbl)&lt;br /&gt;
	renderTree(tbl)&lt;br /&gt;
	return tostring(tbl)&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Programmer</name></author>
	</entry>
</feed>