我目前正在制作一个足球在线经理游戏,我被困在试图生成比赛。
这是我的SQL结构:
id: integer
home: integer (home team)
away: integer (away team)
date: integer
league: integer我的联赛将包含许多球队,所以一支球队将无法与所有其他球队竞争。
到目前为止,我的解决方案是遍历所有可能的匹配,然后给它一个唯一的日期(基于一定数量的给定日期)。然而,这是行不通的,因为我有太多的球队在联赛。
逻辑:
联盟:
我没有任何代码要展示,因为我的代码已经变得不相关了(因为我在寻找不同的解决方案)。我不是在找完整的代码,只要指引我的方向。
* UPDATE *
foreach ($teams as $team_home) { foreach ($teams as $team_away) { if ($team_home === $team_away)继续;if (!isset($代表$team_home->id))$代表$team_home->id= 0;if (!isset($代表$team_away->id))$代表$team_away->id= 0;if ($代表$team_away->id == count($dates)/2)继续;$matches[] =数组( 'home‘=> $ => _home->id,’=> $team_away->id,>id;$代表$team_home->id ++;$代表$team_away->id++;if ($代表$team_home->id == count($dates)/2)中断;}}
所代表的数组记录了球队作为主场和客场的比赛次数。请注意,球队最多可以有50%的日期作为主场比赛。
示例输出:
阵列(1 =>阵列(家庭=> 14离开=> 14 )2 =>阵列(离开=> 14家=> 14 )……25 =>阵列(离开=> 9家庭=> 9)
正如你所看到的,最后一支球队没有像其他球队那样打14场主场和客场比赛。
发布于 2013-11-29 23:11:05
一次做的太多了。在联盟中有24支球队,这意味着每支球队要打46场比赛(另外23支球队一家一场)。
所以现在你有46个位置要放火柴。
Choose a team at random
Generate those 46 matches ,assign into the slots in some random order.
Randomly Choose the next team
Generate their 46 matches, look for those that have already been assigned and set their slot
Randomly fill the rest.
Keep going until you have one team remaining, which should already be done...然后你可以指定日期..。
可以在SQL中做到这一点,但几乎可以肯定的是,PHP更好地表达了这一点。
https://stackoverflow.com/questions/20294265
复制相似问题