1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
##############################################################################
# Check Adversaire
##############################################################################
def CheckAdversaire(Trouve,MyList01,MyList02):
Trouve=False
nb=0
while nb<16:
if MyList02[nb] not in MyList01:
pass
else:
MyVal=MyList01.index(MyList02[nb])
if MyVal in [0,4,8,12]:
decalage=2
if MyVal in [1,5,9,13]:
decalage=1
if MyVal in [2,6,10,14]:
decalage=-2
if MyVal in [3,7,11,15]:
decalage=-3
pos01=MyVal+decalage
pos02=MyVal+decalage+1
if nb in [0,4,8,12]:
if MyList02[nb+2]==MyList01[pos01] or MyList02[nb+2]==MyList01[pos02] or MyList02[nb+3]==MyList01[pos01] or MyList02[nb+3]==MyList01[pos02]:
Trouve=True
return Trouve
if nb in [1,5,9,13]:
if MyList02[nb+1]==MyList01[pos01] or MyList02[nb+1]==MyList01[pos02] or MyList02[nb+2]==MyList01[pos01] or MyList02[nb+2]==MyList01[pos02]:
Trouve=True
return Trouve
if nb in [2,6,10,14]:
if MyList02[nb-1]==MyList01[pos01] or MyList02[nb-1]==MyList01[pos02] or MyList02[nb-2]==MyList01[pos01] or MyList02[nb-2]==MyList01[pos02]:
Trouve=True
return Trouve
if nb in [3,7,11,15]:
if MyList02[nb-2]==MyList01[pos01] or MyList02[nb-2]==MyList01[pos02] or MyList02[nb-3]==MyList01[pos01] or MyList02[nb-3]==MyList01[pos02]:
Trouve=True
return Trouve
nb+=1
return Trouve
##############################################################################
# initialisation
##############################################################################
#NomFemme = ["Susanne","Isabelle","Annaig","Jaqueline","Svenja","Heide","Sabine","Carola","Soazic","Nolwenn","Birgit"]
#NomHomme = ["Frank N.","Stephane","Thomas","Jochen","Frank S.","Bernd","Paul","Marcel","Marcus","Alexander"]
NomFemme = ["Susanne","Isabelle","Annaig","Jaqueline","Svenja","Heide","Sabine","Carola","Soazic"]
NomHomme = ["Frank N.","Stephane","Thomas","Jochen","Frank S.","Bernd","Paul","Marcel"]
NbPlayer=len(NomFemme)+len(NomHomme)
TennisPlace = int(NbPlayer / 4)
NbExempt = NbPlayer - TennisPlace * 4
ExemptF = len(NomFemme) - TennisPlace * 2
ExemptH = len(NomHomme) - TennisPlace * 2
print("NbPlayer",NbPlayer,"nbFemme",len(NomFemme),"nbHomme",len(NomHomme),"TennisPlace",TennisPlace,"NbExempt",NbExempt,"ExemptF",ExemptF,"ExemptH",ExemptF)
##############################################################################
# Création de toutes les paires mixtes de joueurs
##############################################################################
from itertools import combinations
A=list(combinations(list(range(1,NbPlayer+1)),2))
lenA=len(A)-1
while lenA!=-1:
B=list(A[lenA])
if B[0]%2 != 0 and B[1]%2 != 0:
del A[lenA]
if B[0]%2 == 0 and B[1]%2 == 0:
del A[lenA]
lenA-=1
#print("Liste des couples:",A)
#print("Nombre de couples",len(A))
##############################################################################
# rounds
##############################################################################
from random import *
MaListe=[]
RoundToPlay,k=0,0
Trouve=False
while RoundToPlay < 5:
Couple=0
C=[]
while Couple < TennisPlace*2:
hasard=randrange(0,len(A))
B=A[hasard]
while B[0] in MaListe or B[1] in MaListe:
k+=1
if k > 3000:
break
hasard=randrange(0,len(A))
B=A[hasard]
MaListe.append(B[0])
MaListe.append(B[1])
C.append(A[hasard])
del A[hasard]
Couple+=1
##############################################################################
# test si un joueur a déjà eu le(s) même(s) adversaire(s)
##############################################################################
if RoundToPlay == 0:
round01=MaListe
MaListe=[]
if RoundToPlay == 1:
round02=MaListe
MaListe=[]
MyList01=round01
MyList02=round02
# print("round01",round01,"round02",round02)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
if RoundToPlay == 2:
round03=MaListe
MaListe=[]
MyList01=round01
MyList02=round03
# print("round01",round01,"round03",round03)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
MyList01=round02
MyList02=round03
# print("round02",round02,"round03",round03)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
if RoundToPlay == 3:
round04=MaListe
MaListe=[]
MyList01=round01
MyList02=round04
# print("round01",round01,"round04",round04)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
MyList01=round02
MyList02=round04
# print("round02",round02,"round04",round04)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
MyList01=round03
MyList02=round04
# print("round03",round03,"round04",round04)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
if RoundToPlay == 4:
round05=MaListe
MaListe=[]
MyList01=round01
MyList02=round05
# print("round01",round01,"round05",round05)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
MyList01=round02
MyList02=round05
# print("round02",round02,"round05",round05)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
MyList01=round03
MyList02=round05
# print("round03",round03,"round05",round05)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
MyList01=round04
MyList02=round05
# print("round04",round04,"round05",round05)
Trouve=CheckAdversaire(Trouve,MyList01,MyList02)
if Trouve==False:
RoundToPlay+=1
else:
A.extend(C)
##############################################################################
# affichage
##############################################################################
#print("Nombre de couples restants",len(A),"Liste des couples restants:",A)
round01.sort()
round02.sort()
round03.sort()
round04.sort()
round05.sort()
print("round01",list(set(round01)))
print("round02",list(set(round02)))
print("round03",list(set(round03)))
print("round04",list(set(round04)))
print("round05",list(set(round05))) |
Partager