@TaeHunKim/

# TennisTeam

## No description

Files
• main.py
main.py
```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
```
```from copy import copy, deepcopy

# Config
GroupA = ["A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8"]
GroupB = ["B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8"]
numBattleBetweenTwo = 2
Debug = False

# Initialization
lenA = len(GroupA)
lenB = len(GroupB)
lenAB = lenA+lenB
pairnum = min([lenA, lenB])
pairedge = [[1 for x in range (lenB)] for y in range(lenA)]
battleedge = [[numBattleBetweenTwo for x in range (lenAB)] for y in range(lenAB)]

for x in range(lenAB):
battleedge[x][x] = 0

# Make the rounds
roundlist = []
while True:
leftPairEdge = sum(sum(pairedge, []))
leftBattleEdge = sum(sum(battleedge, []))
if Debug:
print("Inside Round Loop")
print("Left Pair Edge: " + str(leftPairEdge))
print("Left Battle Edge: " + str(leftBattleEdge))
if leftPairEdge < pairnum: break
if leftBattleEdge < pairnum/2: break

battlelist = []
usedA = []
usedB = []
while len(battlelist) < pairnum/2:
if Debug:
leftPairEdge = sum(sum(pairedge, []))
leftBattleEdge = sum(sum(battleedge, []))
print("Inside Battle Loop")
print("Left Pair Edge: " + str(leftPairEdge))
print("Left Battle Edge: " + str(leftBattleEdge))
print("usedA: " + str(usedA))
print("usedB: " + str(usedB))
if leftPairEdge < pairnum: break
if leftBattleEdge < pairnum/2: break

# Find the first pair edge which is still possible
firstpair = (-1, -1)
for a in range(lenA):
if firstpair != (-1, -1): break
if a in usedA: continue
for b in range(lenB):
if b in usedB: continue
if pairedge[a][b] == 1:
firstpair = (a, b)
break
if firstpair == (-1, -1):
if Debug:
print("Finding first pair failed!")
break

# Find the second pair edge which is still possible
# and can have a battle with the first pair
secondpair = (-1, -1)
for a in range(lenA):
if secondpair != (-1, -1): break
if a in usedA: continue
if a == firstpair[0] : continue
for b in range(lenB):
if b in usedB: continue
if b == firstpair[1]: continue
if pairedge[a][b] == 1:
fa = firstpair[0]
fb = firstpair[1]
if battleedge[fa][a] > 0 and battleedge[fa][lenA+b] > 0 and battleedge[lenA+fb][a] > 0 and battleedge[lenA+fb][lenA+b] > 0:
secondpair = (a, b)
break
elif Debug:
print("battleedge[{0}][{1}] = {2}".format(fa, a, battleedge[fa][a]))
print("battleedge[{0}][{1}] = {2}".format(fa, b, battleedge[fa][lenA+b]))
print("battleedge[{0}][{1}] = {2}".format(fb, a, battleedge[lenA+fb][a]))
print("battleedge[{0}][{1}] = {2}".format(fb, b, battleedge[lenA+fb][lenA+b]))
elif Debug:
print("pairedge[{0}][{1}] == 0".format(a, b))

if secondpair == (-1, -1):
if Debug:
print("Removed First pair: " + str(firstpair))
# the first pair is useless..
pairedge[firstpair[0]][firstpair[1]] = 0
continue

battlelist.append((firstpair, secondpair))
fa = firstpair[0]
fb = firstpair[1]
sa = secondpair[0]
sb = secondpair[1]
battleedge[fa][sa] -= 1
battleedge[fa][lenA+sb] -= 1
battleedge[lenA+fb][sa] -= 1
battleedge[lenA+fb][lenA+sb] -= 1
battleedge[sa][fa] -= 1
battleedge[sa][lenA+fb] -= 1
battleedge[lenA+sb][fa] -= 1
battleedge[lenA+sb][lenA+fb] -= 1
pairedge[fa][fb] = 0
pairedge[sa][sb] = 0
usedA.append(fa)
usedA.append(sa)
usedB.append(fb)
usedB.append(sb)

if len(battlelist) == pairnum/2:
roundlist.append(battlelist)
else:
break

# Print the rounds
for round in roundlist:
""" a1/b1 VS a2/b2, a3/b3 VS a4b4, a5b5 VS a6b6, a7b7 VS a8b8"""
roundstr = ""
for battle in round[:-1]:
roundstr += GroupA[battle[0][0]] + "/" + GroupB[battle[0][1]] + " VS " + GroupA[battle[1][0]] + "/" + GroupB[battle[1][1]] + ", "
battle = round[-1]
roundstr += GroupA[battle[0][0]] + "/" + GroupB[battle[0][1]] + " VS " + GroupA[battle[1][0]] + "/" + GroupB[battle[1][1]]
print(roundstr)
```
Fetching token