目前我实际上正在寻找一个针对我的问题的术语:
我创建了一个> 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轮比赛中可以进行测试)
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;
}
}
}
}
}
对于我将谷歌的任何帮助将不胜感激
答案 0 :(得分:3)
Swiss system“是一种非消除锦标赛格式,其中包含预定数量的竞赛 em>,但与循环赛相比,更少比赛”。
它广泛用于国际象棋和其他游戏。根据维基百科:
瑞士系统通常用于国际象棋,桥牌,电子竞技,莫拉巴拉巴,拼字游戏,步步高,壁球,法式滚球,测验碗,魔术:聚会,政策辩论,战锤,八球,黑白棋,自治领,神奇宝贝TCG,Yu-Gi-Oh,Blood Bowl,Guild Wars 2,星球大战:X-Wing Miniatures游戏,流亡之路和Android:Netrunner。
它可能符合您的需求,您可以找到一些即用型实施。