单败淘汰赛 Bracket C# Razor pages

问题描述 投票:0回答:0

我有这段代码,我想在其中生成一个单消括号。此代码正在生成括号,但它不适用于消除逻辑。例如,在一个括号中有印度 vs 巴基斯坦,印度被淘汰但仍在下一轮印度来了我希望每对括号一旦球队被淘汰就不应该进入下一轮。

这是我的代码:

@{
string[] team_names = new string[] { "Pakistan", "India", "Germany", "Bangladesh", "Saudi", "Emarat", "Morocco", "Nepal" };
int num_teams = team_names.Length;
int total_rounds = (int)Math.Floor(Math.Log(num_teams, 2)) + 1;
int max_rows = num_teams * 2;
int[] team_array = new int[total_rounds + 1];
bool[] unpaired_array = new bool[total_rounds + 1];
bool[] score_array = new bool[total_rounds + 1];

for (int round = 1; round <= total_rounds; round++)
{
    team_array[round] = 1;
    unpaired_array[round] = false;
    score_array[round] = false;
}
}

HTML

<table border="1" cellspacing="1" cellpadding="1">
<tr>
    @for (int round = 1; round <= total_rounds; round++)
    {
        <td colspan="2"><strong>Round @round</strong></td>
    }
</tr>
@for (int row = 1; row <= max_rows; row++)
{
    <tr>
        @for (int round = 1; round <= total_rounds; round++)
        {
            int score_size = (int)Math.Pow(2, round) - 1;
            if (is_player(round, row, team_array[round]))
            {
                unpaired_array[round] = !unpaired_array[round];
                <td>@team_names[team_array[round]-1]</td>
                <td width="20">&nbsp;</td>
                team_array[round]++;
                score_array[round] = false;
            }
            else
            {
                if (unpaired_array[round] && round != total_rounds)
                {
                    if (!score_array[round])
                    {
                        <td rowspan="@score_size">Score</td>
                        <td rowspan="@score_size" width="20">@round</td>
                        score_array[round] = true;
                    }
                }
                else
                {
                    <td colspan="2">&nbsp;</td>
                }
            }
        }
    </tr>
}

@代码{}

bool is_player(int round, int row, int team)
{
    return row == (int)Math.Pow(2, round - 1) + 1 + (int)Math.Pow(2, round) * (team - 1);
}

我希望这段代码适用于 2 的幂的团队,并为所有团队生成单败淘汰赛。

c# razor logic razor-pages tournament
© www.soinside.com 2019 - 2024. All rights reserved.