python模拟足球射门,Python(足球游戏算法的麻烦)

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))

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:

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

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

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

and how to do that for 6 teams or for 7 teams?

please help!!!

mb i explained bad:

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']

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 points

draft 1 point

loose - 0 points

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.

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

解决方案

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.

The set that needs to be covered consists of:

a combination of each team and each match day

every match pairing

which for four teams is:

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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值