# Random Pairing

Harry George harry.g.george at boeing.com
Tue Jul 6 14:50:47 EDT 2004

knowlj at hotmail.com (Jared) writes:

> 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.

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.

--
harry.g.george at boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007