2016-11-17 93 views
2

目前我實際上是尋找特定的我的問題的一個術語:聯賽調度不ROUNDROBIN

我創建> 4隊 聯盟聯賽持續3個回合(編號爲簡單起見) ,對位應從隊中尚未比賽的隊伍中隨機分配。

我很努力地讓我現有的代碼與每個邊緣案例一起運行,所以我想查找爲這種案例開發的'標準'algorythm,但我不能拿出我期待的術語。

一個計劃的例子是:

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支球隊進行測試,在Round3可能發生)

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;  
       } 
      } 
     } 
    } 
} 

任何幫助爲我應谷歌,將不勝感激

回答

3

Swiss system「是設有輪競爭的的預定數量的非消除比賽格式,但相當少比在循環賽」。

它廣泛用於國際象棋和其他遊戲。根據維基百科:

瑞士系統在國際象棋,橋牌,電子競技,十二子直棋,拼字遊戲,步步高,壁球,地擲球(滾球),測驗碗,魔術常用的有:收集,政策辯論,戰錘,八球,Reversi,Dominion,神奇寶貝TCG,Yu-Gi-Oh,Blood Bowl,激戰2,星球大戰:X-Wing Miniatures遊戲,流放之路和Android:Netrunner。

它可能適合您的需求,您可以找到一些隨時可用的實現。

+0

所以我基本上搜索瑞士系統_沒有得分的東西。 我會盡力找到這方面的東西,謝謝:) – user1021605