Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. import random
  2. import math
  3. def randomRound(Competitors, roundNumber, nextRound): #Randomizes the rounds by choosing 2 random competitors
  4. while len(Competitors) >> 0:
  5. randomNumber1 = random.randint(0, len(Competitors)-1) #chooses random number
  6. Competitor1 = Competitors[randomNumber1] #uses the random number to get the first compeitor for the match
  7. Competitors.remove(Competitor1)
  8. randomNumber2 = random.randint(0, len(Competitors)-1) #chooses random number
  9. Competitor2 = Competitors[randomNumber2] #uses the random number to get the first compeitor for the match
  10. Competitors.remove(Competitor2)
  11. roundNumber += 1
  12. nextRound.append(Competitor1)
  13. nextRound.append(Competitor2)
  14. print 'Match #', roundNumber, Competitor1, 'vs ', Competitor2
  15. return roundNumber
  16.  
  17.  
  18. def startRound(roundNumberChecker, winners, nextRound, roundNumber, byes): #asks who won each match and sets up matches for the next round
  19. winners = []
  20. ready = raw_input('Type "y" to continue the next round ') #wait to ask until user is ready
  21. if ready == 'y':
  22. pass
  23. else:
  24. ready = raw_input('Invalid input. When finished type "y" to continue to the next round ')
  25. while len(nextRound) > 1: #asks who won each match
  26. winner = raw_input('Type in the winner of match #{}: '.format(roundNumberChecker+1))
  27. if winner == nextRound[0]: #checks if the input is a valid winner of the match
  28. winners.append(nextRound[0])
  29. nextRound.remove(nextRound[0])
  30. nextRound.remove(nextRound[0])
  31. roundNumberChecker += 1
  32. elif winner == nextRound[1]:
  33. winners.append(nextRound[1])
  34. roundNumberChecker += 1
  35. nextRound.remove(nextRound[0])
  36. nextRound.remove(nextRound[0])
  37. else:
  38. print 'Invalid winner'
  39.  
  40.  
  41. print 'Next Round'
  42. winners = winners + byes #buts the compeitors with byes into the next round
  43. while len(winners) > 1: #sets up the next matches in order
  44. print 'Match #{}:'.format(roundNumber+1), winners[0], 'vs ', winners[1]
  45. nextRound.append(winners[0])
  46. winners.remove(winners[0])
  47. nextRound.append(winners[0])
  48. winners.remove(winners[0])
  49. roundNumber +=1
  50. if len(winners) == 1: #if there was only one winner left the champion is revealed
  51. print winners[0] + ' is the champion! Congratulations ' + winners[0] + '!'
  52. else:
  53. pass
  54. return nextRound
  55.  
  56.  
  57. def bracketmaker():
  58. roundNumberChecker = 0 #match number for when checking who won
  59. nextRound=[] #list that holds all competitors from the current round
  60. winners=[] #list that holds winners of the round
  61. byeNumber = 0 #bye number for the people with byes
  62. competitorCounter = 0 #how many competitors there are
  63. Competitors = [] #list that holds competitor names
  64. roundNumber = 0 #counts up for the match numbers
  65. byes = [] #list that holds the competitors with byes
  66.  
  67. numCompetitors = int(raw_input('Enter number of competitors: ')) #input how many competitors
  68. if numCompetitors <= 1:
  69. print 'Error. Please enter a value greater than 1.' #if 1 then a bracket is not need and an error is given
  70. numCompetitors = (raw_input('Enter number of competitors: '))
  71. else:
  72. pass
  73. while numCompetitors >= 1: #input the name of each competitor
  74. Competitor = (raw_input('Enter competitor #{}: '.format(competitorCounter+1)))
  75. Competitors.append(Competitor)
  76. numCompetitors = numCompetitors-1
  77. competitorCounter = competitorCounter+1
  78. else:
  79. pass
  80. if math.log(len(Competitors), 2.0).is_integer(): #if there are a power of 2 competitors then no byes are needed
  81. randomRound(Competitors, roundNumber, nextRound) #runs randomize round
  82. else:
  83. k = math.log(len(Competitors), 2.0) #calculates the log
  84. float(k)
  85. byeNum = int(2**round(k + .5) - len(Competitors)) #rounds the log up to the next whole number for how many byes are needed
  86. while byeNum > 0:
  87. randomNumber3 = random.randint(0, len(Competitors)-1) #chooses a random number
  88. competitorBye = Competitors[randomNumber3] #uses the random number to select who gets the bye
  89. Competitors.remove(competitorBye)
  90. byeNum -= 1
  91. byes.append(competitorBye)
  92. print 'Bye #{} '.format(byeNumber+1), competitorBye
  93. byeNumber += 1
  94. else:
  95. randomRound(Competitors, roundNumber, nextRound) #runs the round randomizer
  96. while len(nextRound) > 1: #runs the next round function when there is more than one competitor left
  97. nextRound = startRound(roundNumberChecker, winners, nextRound, roundNumber, byes)
  98. byes = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement