100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 欧冠16强抽签概率计算器

欧冠16强抽签概率计算器

时间:2023-11-11 13:45:10

相关推荐

欧冠16强抽签概率计算器

一时心起,随便写了一个欧冠16强抽签概率计算器,计算各支球队可能抽到的对手和对应的概率,考虑同国回避和同组回避原则。

当然,花的时间少,写的很烂,能用就行,输出直接搞命令行,性能不考虑,直接全排列简单粗暴,也没考虑扩展和复用什么的,程序也很简短……以后再要用的时候直接改就可以了……

# coding = utf-8'''Module: uclDrawCalCreated on -12-10@author: Ring'''import itertoolsclass team:def __init__(self, teamName="", teamGroup="", teamCountry="", teamRanking="1"):self.name = teamNameself.group = teamGroupself.country = teamCountryself.ranking = teamRankingdef printTeam(self):print self.name, "-", self.country, "-", self.group+self.rankingdef isDrawCorrect(list1, list2):for i in range(0,8):if (list2[i].group == list1[i].group) or (list2[i].country == list1[i].country):return Falsereturn Truedef getProbabilityByTeam(list1, list2, allResult2, index):print list1[index].nametotalCount = 0proList = {list2[0].name:0, list2[1].name:0, list2[2].name:0, list2[3].name:0, \list2[4].name:0, list2[5].name:0, list2[6].name:0, list2[7].name:0}for someResult in allResult2:if isDrawCorrect(list1, someResult):totalCount += 1proList[someResult[index].name] += 1else:passfor i in range(0, 8):print "draw: ", list2[i].name, " probability: ", proList[list2[i].name]*1.0/totalCountrealmadrid = team("Real Madrid", "A", "Spain", "1")wolfsburg = team("Wolfsburg", "B", "Germany", "1")atmadrid = team("A.T.Madrid", "C", "Spain", "1")mancity = team("Man City", "D", "England", "1")barcelona = team("Barcelona", "E", "Spain", "1")bayernmunich = team("Bayern Munich", "F", "Germany", "1")chelsea = team("Chelsea", "G", "England", "1")zenit = team("Zenit", "H", "Russia/Ukraine", "1")paris = team("Paris Saint Germain", "A", "France", "2")psv = team("PSV", "B", "Holland", "2")benfica = team("Benfica", "C", "Portugal", "2")juventus = team("Juventus", "D", "Italy", "2")roma = team("Roma", "E", "Italy", "2")arsenal = team("Arsenal", "F", "England", "2")kyiv = team("Dinamo Kyiv", "G", "Russia/Ukraine", "2")gent = team("Gent", "H", "Danmark", "2")listFirst = [realmadrid, wolfsburg, atmadrid, mancity, barcelona, bayernmunich, chelsea, zenit]listSecond = [psv, benfica, juventus, roma, arsenal, kyiv, gent, paris]firstAllResult = list(itertools.permutations(listFirst, len(listFirst)))secondAllResult = list(itertools.permutations(listSecond, len(listSecond)))def main():for i in range(0, 8):getProbabilityByTeam(listFirst, listSecond, secondAllResult, i)for j in range(0, 8):getProbabilityByTeam(listSecond, listFirst, firstAllResult, j)main()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。