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
| p0 = Worksheets("Sheet1").Cells(2, 2)
q0 = Worksheets("Sheet1").Cells(3, 2)
p = 2 ^ p0 '=== Nb de poules
q = 2 ^ q0 '=== Nb de players
n = p * q
For i = 1 To p
For j = 1 To q
b(i, j) = True
Next j
Next i
no = 1
While no < p0 + q0 '======== no: No du tour
i = 0
j = 1
count = 0
While count < n / (2 ^ no)
i = i + 1
If i > p Then
i = 1
j = j + 1
End If
While b(i, j) = False
i = i + 1
If i > p Then
i = 1
j = j + 1
End If
Wend
v = cand((i), (j), b, (p), (q))
count = count + 1
match(count, 1) = i
match(count, 2) = j
match(count, 3) = v(1)
match(count, 4) = v(2)
b(i, j) = False
b(v(1), v(2)) = False
Wend
Worksheets("Sheet1").Cells(1, 4 + no) = "Tour No " & no & ":"
For i = 1 To count
Worksheets("Sheet1").Cells(1 + i, 4 + no) = "(" & match(i, 1) & "." & match(i, 2) & "," & match(i, 3) & "." & match(i, 4) & ")"
Next i
'============= tirage aléatoire des victorieux
For i = 1 To p
For j = 1 To q
b(i, j) = True
Next j
Next i
Worksheets("Sheet1").Cells(3 + count, 4 + no) = "Victorieux:"
For i = 1 To count
If Rnd < 0.5 Then
Worksheets("Sheet1").Cells(4 + count + i, 4 + no) = "'(" & match(i, 1) & "." & match(i, 2) & ")"
b(match(i, 1), match(i, 2)) = False
Else
Worksheets("Sheet1").Cells(4 + count + i, 4 + no) = "'(" & match(i, 3) & "." & match(i, 4) & ")"
b(match(i, 3), match(i, 4)) = False
End If
Next i
no = no + 1
Wend
End Sub
Function cand(i As Integer, j As Integer, b() As Boolean, p As Integer, q As Integer) As Variant
Dim ecart As Integer, val As Integer, v As Integer, w As Integer
Dim sol(2) As Variant
ecart = 0
sol(1) = 0
For k = 1 To p
For l = 1 To q
If b(k, l) = True Then
v = Abs(i - k)
w = v + Abs(j - l)
If w > ecart Or (w = ecart And v > Abs(i - sol(1))) Then
ecart = w
sol(1) = k
sol(2) = l
End If
End If
Next l
Next k
cand = sol
End Function |
Partager