php - 没有循环赛的联赛安排

标签 php tournament matchmaking sports-league-scheduling-problem

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

我创建了一个由超过 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

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

这是我当前创建一轮的代码。可能会发生这样的情况,此代码不会在第 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;    
               }
           }
        }
    }
}

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

最佳答案

一个Swiss system “是一种非淘汰赛形式,其特点是预定比赛轮数,但比循环赛很多”。

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

Swiss systems are commonly used in chess, bridge, eSports, Morabaraba, Scrabble, Backgammon, squash, Pétanque (boules), Quiz bowl, Magic: The Gathering, Policy Debate, Warhammer, eight-ball, Reversi, Dominion, Pokémon TCG, Yu-Gi-Oh, Blood Bowl, Guild Wars 2, Star Wars: X-Wing Miniatures Game, Path of Exile and Android: Netrunner.

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

关于php - 没有循环赛的联赛安排,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40644820/

相关文章:

unity-game-engine - 如何使用 Photon Engine 阻止特定用户进行随机匹配?

c - C 中的配对程序?

php - 有没有办法在使用 php explode 或其他类似功能时保留定界符?

javascript - 使用 MySql 数据填充 JavaScript 数组

php - 在每个页面上包含菜单

java - 单场淘汰赛算法

c# - Unity 2018.2 - UNet 对接会仅适用于 LAN

javascript - 如何从 PHP 向 Javascript 发送变量?

algorithm - 对于超过两名参赛者的回合,什么算法可以生成循环赛 "pairings"?

c# - 双败赛数据结构