Python(足球游戏算法的麻烦) [英] Python (football games algorithm troubles)

查看:473
本文介绍了Python(足球游戏算法的麻烦)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为足球小组赛编写算法。例如,
:我在舞台上有4个队伍。

I am trying to write algorithm for football group stage. for example: i have 4 teams in the stage.

 teams = ['team1', 'team2', 'team3', 'team4']

然后我得到了所有唯一的对

then i got an all unique pairs

import itertools
team_pairs = list(itertools.combinations(teams, 2))

我的team_pairs是团队之间的唯一匹配

my team_pairs are unique matches between teams

[('team1', 'team2'), ('team1', 'team3'), ('team1', 'team4'), ('team2', 'team3'), ('team2', 'team4'), ('team3', 'team4')]

以及现在。我如何创建所有回合?例如

and now. how can i create all rounds? for example:


  • 第一轮:('team1','team2')('team3' ,'team4')

  • 第二轮:('team1','team3')('team2','team4')

  • 第二轮:('team1','team4')('team2','team3')

  • round1: ('team1', 'team2') ('team3', 'team4')
  • round2: ('team1', 'team3') ('team2', 'team4')
  • round2: ('team1', 'team4') ('team2', 'team3')

如何为6支球队或7支球队做到这一点?
请帮忙!!!

and how to do that for 6 teams or for 7 teams? please help!!!

mb我解释不好:

我有11支队伍。然后我将它们分成几组。
和我有:

i have an 11 teams. Then i break them into groups. and i have:


  • group1:['team1','team2','team3','team4']

  • group2:['team1','team2','team3','team4']

  • group3:['team1','team2' ,'team3']

在每个组中,团队必须与该组中的所有团队一起比赛。
参加1组,团队为:

in each group, the team must play with all teams in group. lets take 1 group, teams are:

teams = ['team1', 'team2', 'team3', 'team4']

win-3分
草案1分
宽松-0分

win - 3 points draft 1 point loose - 0 points

他们不能一次玩所有人。
他们玩了3天。

they can't play everybody at one time. they are playing 3 days.

* first day - team1 vs team2 and team3 vs team4
* second day - team1 vs team3 and team2 vs team4
* third day - team1 vs team4 and team2 vs team3

然后我可以总结积分。

then i can summ points.

但是我实际上并不了解如何按天划分小组(我的team_pairs),以及哪一天在哪支球队比赛。

But i don't actually understand how to split my group (my team_pairs) by days and what team play in what day.

推荐答案

问题可以看作是确切的封面问题,可以像数独一样使用 Algorithm X 来解决。在网络上有 Python实现

The problem can be seen as an exact cover problem and can be solved like a Sudoku with Algorithm X, of which there are Python implementations available on the web.

需要涵盖的范围包括:


  • 每个团队和每个比赛日的组合

  • 每次比赛配对

其中四支球队是:

A1, A2, A3, B1, B2, B3, C1, C2, C3, D1, D2, D3, AB, AC, AD, BC, BD, CD

其中 B3 表示团队 B 在第<$ c天$ c> 3 和 BD 表示团队 B 扮演团队 D

where B3 means team B plays on day 3 and BD means team B plays team D.

可用子集是所有比赛配对和所有比赛日的组合,对于四支球队而言:

The available subsets are all match pairings combined with all match days, which for four teams is:

AB1: A1, B1, AB
AB2: A2, B2, AB
AB3: A3, B3, AB
AC1: A1, C1, AC
...
CD3: C3, D3, CD

解决这个问题会产生很多可能的结果,实质上是球队和比赛日的排列。选择一个,按比赛日排序并比赛。

Solving this yields a great many possible fixtures, essentially permutations of teams and match days. Pick one, order by match day and play.

如果球队数量奇数,没有解决方案。添加一个空团队作为虚拟对象,并且不参加其中一方是虚拟对象的比赛。

There are no solutions if there is an odd number of teams. Add a null team as dummy and don't play the matches where one of the sides is the dummy.

这篇关于Python(足球游戏算法的麻烦)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆