2

目前我实际上正在寻找一个专门针对我的问题的术语:

我创建了一个超过 4 支球队的联赛 联赛持续 3 轮(为了简单起见,编号) 比赛应从一支球队尚未交战的球队中随机分配。

我正在努力让我当前的代码在每个边缘情况下运行,所以我想查找为这种情况开发的“标准”算法,但我无法想出我正在寻找的术语。

一个时间表示例是:

TeamA: C,E,B
TeamB: F,H,A
TeamC: A,D,H
TeamD: G,C,F
TeamE: H,A,G
TeamF: B,G,D
TeamG: D,F,G
TeamH: E,B,C

在这方面我找不到任何东西,因为这似乎是一个非常非常不可能在联赛/锦标赛中使用的东西——但这是我的要求。

这是我当前创建 ONE Round 的代码。可能会发生,此代码不会在第 3 轮中为每个团队分配一个对手,因为他们可能的对手在本轮已经分配了一场比赛(测试了 6 支球队,可能在第 3 轮中发生)

 public function CalculateDivision()
{
     $teams = Division::find(1)->teams()->get();
     $diffs = array();
     foreach($teams as $team)
     {
//Get possible Opponents
         $opp = Division::find(1)->teams()->where('id','!=',$team->id)->lists('id');
         $matches = $team->matches()->get();
         $plyd = array();
         foreach($matches as $match)
         {   
//Find Opponents a team already has played against
             $plyd[] = $match->teams()->where('id','!=',$team->id)->pluck('id');    

         }
//Substract Opponents already played against from possible Opponents
         $TBP = array_diff($opp,$plyd);
         $diffs[$team->id] = $TBP;
     }
//Order By Least possible Opponents possible
     asort($diffs);
     $this->CalculateMatches($diffs);
}

private function CalculateMatches($teams)
{
//$teams equals $teams[teamID] = [Opponent1ID,Opponent2ID ...]
    $setTeams = array();
    foreach($teams as $key => $team)
    {
//If Team hasn't already a new matchup find opponent from their possible opponent array
        if(!in_array($key,$setTeams))
        {
           shuffle($team);
           foreach($team as $opponent)
           {
//If possible opponent hasn't already a matchup create one, add both teams to 'has already a match' so the loop doesn't evaluate them again
               if(!in_array($opponent,$setTeams))
               {
                   $this->CreateMatch($key,$opponent);
                   $setTeams[] = $key;
                   $setTeams[] = $opponent;
                   break;    
               }
           }
        }
    }
}

对我将谷歌搜索的任何帮助将不胜感激

4

1 回答 1

3

瑞士系统“是一种非淘汰赛形式,具有预定轮数的比赛,但比循环赛要少得多”。

它广泛用于国际象棋和其他游戏。根据维基百科:

瑞士系统常用于国际象棋、桥牌、电子竞技、Morabaraba、拼字游戏、双陆棋、壁球、滚球(滚球)、智力竞赛、万智牌、政策辩论、战锤、八球、黑白棋、Dominion、神奇宝贝 TCG、Yu -Gi-Oh、Blood Bowl、激战 2、星球大战:X 翼微型游戏、流放之路和 Android:Netrunner。

它可能适合您的需求,并且您可以找到一些现成的实现。

于 2016-11-17T08:22:31.740 回答