Random Pairing

J

John Hunter

Jared> For a tournament I'm making a random pairing generator. I
Jared> haven't quite figured out how to randomly pair yet though.
Jared> Here's what I have so far:

Assuming you have 100 players, you can shuffle the index vector and
use zip to create a sequence of pairs
from random import shuffle
ind = range(100)
shuffle(ind)
pairs = zip(ind[::2], ind[1::2])
print pairs [(3, 51), (88, 73), (41, 62), (14, 38), (90, 2), (58, 26), (72, 19), (77, 89), (0, 30), (74, 49), (95, 67), (92, 60), (86, 76), (27, 25), (65, 22), (96, 23), (66, 43), (57, 12), (59, 54), (70, 55), (82, 61), (64, 40), (16, 85), (31, 48), (78, 52), (39, 53), (17, 13), (99, 5), (45, 71), (4, 9), (97, 83), (8, 7), (15, 56), (42, 84), (94, 91), (75, 29), (33, 80), (68, 28), (21, 1), (10, 37), (18, 93), (98, 32), (50, 36), (44, 11), (34, 69), (24, 79), (6, 46), (20, 35), (63, 87), (81, 47)]
 
J

Jared

For a tournament I'm making a random pairing generator. I haven't
quite figured out how to randomly pair yet though. Here's what I have
so far:

from random import *
import string
import random

prompt1 = "Who is Player 1?\n"
p1 = raw_input(prompt1)

prompt2 = "Who is Player 2?\n"
p2 = raw_input(prompt2)

prompt3 = "Who is Player 3?\n"
p3 = raw_input(prompt3)

prompt4 = "Who is Player 4?\n"
p4 = raw_input(prompt4)
print (p1,p2,p3,p4)

#Randomly pair players
Players[p1,p2,p3,p4]
index = MOD(Random(<Seed>)%3
for i < 4
volume = Player[index]
print p1, "vs.", p2
print p3, "vs.", p4


while 1:
prompt5 = "Who won the in the first pairing?\n"
winner1 = raw_input(prompt5)
prompt6 = "Who won the in the second pairing?\n"
winner2 = raw_input(prompt6)
print winner1, "vs.", winner2
#/ if winner1 = v and winner2 = y
#/ print x, "vs.", z
#/ if winner1 = v and winner2 = z
#/ print x, "vs.", y
#/ if winner1 = v and winner2 = x
#/ print y, "vs.", z

#Pair the winner vs. the winner and the loser vs. the loser
y = raw_input(prompt5)#input didn't work

if str(y) == 'Exit' or str(y) == 'exit':
break
 
H

Harry George

For a tournament I'm making a random pairing generator. I haven't
quite figured out how to randomly pair yet though. Here's what I have
so far:

from random import *
import string
import random

prompt1 = "Who is Player 1?\n"
p1 = raw_input(prompt1)

prompt2 = "Who is Player 2?\n"
p2 = raw_input(prompt2)

prompt3 = "Who is Player 3?\n"
p3 = raw_input(prompt3)

prompt4 = "Who is Player 4?\n"
p4 = raw_input(prompt4)
print (p1,p2,p3,p4)

#Randomly pair players
Players[p1,p2,p3,p4]
index = MOD(Random(<Seed>)%3
for i < 4
volume = Player[index]
print p1, "vs.", p2
print p3, "vs.", p4


while 1:
prompt5 = "Who won the in the first pairing?\n"
winner1 = raw_input(prompt5)
prompt6 = "Who won the in the second pairing?\n"
winner2 = raw_input(prompt6)
print winner1, "vs.", winner2
#/ if winner1 = v and winner2 = y
#/ print x, "vs.", z
#/ if winner1 = v and winner2 = z
#/ print x, "vs.", y
#/ if winner1 = v and winner2 = x
#/ print y, "vs.", z

#Pair the winner vs. the winner and the loser vs. the loser
y = raw_input(prompt5)#input didn't work

if str(y) == 'Exit' or str(y) == 'exit':
break


You may have good reasons for this architecture but one would normally
give it bit more substance:

1. A "model" in the model-view-controller sense, with objects for
players, matches, tiers, etc.

2. A "view" for loading/editing that model. Could be interactive
commandline as you show (even then it should be isolated from the
model), or picked up from a web CGI, or parsed from a spreadsheet
csv, or parsed from an XML, etc.

3. A compute engine to actually do the pairings. E.g., for initial
random pairings, random.shuffle, then take 2 at a time.
Afterwards, you seem to want to do winners with winners and losers
with losers, so we just have the same problem on two different
sequences.

4. A "view" to show the pairings, e.g., a website, or maybe an XMLRPC
service.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top