Fizzer should use this to make 2v2 ladder Matchups :)
Sorry for messy code, you can tell which part I made and which part knyte made.
Edit: Fizzer should not use this to make 2v2 ladder matchups. Fizzer should use the top function for template picking :)
import random
players = []
# can be used in Format of "A, B & C" for Teams
templates=[Guiroma 2v2, Szeurope 2v2, China 2v2, etc]
def tempPicker():
random.shuffle(templates
return templates[0]
def generateRandomTeams(players, teamSize=2):
# given a list of players and a desired team size,
# generates said teams, returned as a list of tuples
random.shuffle(players)
teams = [] # creates an empty list to store team tuples
if len(players) % teamSize != 0:
pass # handle extra players here
# ignore this section if you just want to trim random extras
numTeams = len(players) / teamSize
# calculates # of teams, ignoring extras
# (at this point, they're out of the picture)
for x in xrange(numTeams): # goes from 0 to numTeams - 1
team = list() # generates an empty list to store team members
for i in xrange(teamSize): # goes from 0 to teamSize - 1
team.append(players[(teamSize*x)+i]) # adds a player to the team
# you might have noticed that they follow a pattern
# for each team, you first add the player at the index
# teamSize * teamNumber (x) + 0 (the +0 is important)
# and last add a player at the index
# teamSize * teamNumber (x) + (teamSize - 1)
# for example, with two teams it's player 2*x [0,2,4...]
# and player 2*x + 1 [1,3,5]
# this for loop lets you iterate from 0 to teamSize - 1
# while the outer for loop lets you iterate
# from team 0 to the final team
teams.append(tuple(team))
# adds the tuple (player1,...,playerN) to the list of teams
return teams
def printRandomTeams(players, teamSize=2, separator=" vs "):
teams = generateRandomTeams(players, teamSize)
# generates the random teams
for i in xrange(len(teams)): # goes from 0 to numTeams
# section below uses string formatting
# you should check it out if you haven't already
teamStr = "Game %d: " % (i+1) # just gives you a team number
for player in teams:
# teams[i*] is just the i-th team in the list
teamStr += "%s%s" % (player, separator)
# adds a player name and an " & " (separator)
teamStr = teamStr[:-(len(separator))] + " - " + tempPicker()
# eliminates last " & " because no more players
# recall that a str[:-(x)] is just that string
# without its last x elements
print teamStr
printRandomTeams(players)
Edited 10/3/2015 02:42:48