Random Pairing

Discussion in 'Python' started by John Hunter, Jul 6, 2004.

  1. John Hunter

    John Hunter Guest

    >>>>> "Jared" == Jared <> writes:

    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)]
    >>>
     
    John Hunter, Jul 6, 2004
    #1
    1. Advertising

  2. John Hunter

    Jared Guest

    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
     
    Jared, Jul 6, 2004
    #2
    1. Advertising

  3. John Hunter

    Harry George Guest

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

    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.


    --

    6-6M21 BCA CompArch Design Engineering
    Phone: (425) 342-0007
     
    Harry George, Jul 6, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darren Clark

    Random NOt random?

    Darren Clark, Jun 24, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    490
    mikeb
    Jun 24, 2004
  2. Bush is a Fascist
    Replies:
    17
    Views:
    606
    Thomas G. Marshall
    Aug 22, 2005
  3. Bush is a Fascist

    what do most languages call a name-value pairing?

    Bush is a Fascist, Aug 16, 2005, in forum: C Programming
    Replies:
    15
    Views:
    552
    Jeff Schwab
    Aug 19, 2005
  4. globalrev
    Replies:
    4
    Views:
    818
    Gabriel Genellina
    Apr 20, 2008
  5. VK
    Replies:
    15
    Views:
    1,331
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page