def testCount():
    """
    Test for initial player count,
             player count after 1 and 2 players registered,
             player count after players deleted.
    """
    tournament.deleteMatches()
    tournament.deletePlayers()
    c = tournament.countPlayers()
    if c == '0':
        raise TypeError(
            "countPlayers should return numeric zero, not string '0'.")
    if c != 0:
        raise ValueError(
            "After deletion, countPlayers should return zero. Got {c}".format(c=c))
    print "1. countPlayers() returns 0 after initial deletePlayers() execution."
    tournament.registerPlayer("Chandra Nalaar")
    c = tournament.countPlayers()
    if c != 1:
        raise ValueError(
            "After one player registers, countPlayers() should be 1. Got {c}".format(c=c))
    print "2. countPlayers() returns 1 after one player is registered."
    tournament.registerPlayer("Jace Beleren")
    c = tournament.countPlayers()
    if c != 2:
        raise ValueError(
            "After two players register, countPlayers() should be 2. Got {c}".format(c=c))
    print "3. countPlayers() returns 2 after two players are registered."
    tournament.deletePlayers()
    c = tournament.countPlayers()
    if c != 0:
        raise ValueError(
            "After deletion, countPlayers should return zero.")
    print "4. countPlayers() returns zero after registered players are deleted.\n5. Players can be registered and deleted."
def testRegisterCountDelete():
    tournament.deleteMatches()
    tournament.deletePlayers()
    tournament.registerPlayer("Markov Chaney")
    tournament.registerPlayer("Joe Malik")
    tournament.registerPlayer("Mao Tsu-hsi")
    tournament.registerPlayer("Atlanta Hope")
    c = tournament.countPlayers()
    if c != 4:
        raise ValueError("After registering four players, countPlayers should be 4.")
    tournament.deletePlayers()
    c = tournament.countPlayers()
    if c != 0:
        raise ValueError("After deleting, countPlayers should return zero.")
    print("5. Players can be registered and deleted.")
def getRound(tid=100):
    '''
    getRound(): return the current round of the Tournament, if the last
    round is complete, and the next round

    Argument: tid

    Return: Tournament round, Boolean for last round complete, Tournament next round
    '''
    playerCount = tour.countPlayers(tid)

    # number of rounds in Swiss Pairing is based on number of players
    # need calculatedRounds to know when Tournament is finished
    #   i.e., current round > calculatedRounds
    calculatedRounds = int(ceil(log(playerCount,2)))
    standings = tour.playerStandings(tid)
    sumMatches = 0
    for playerStatistics in standings:
        pid,name,wins,matches = playerStatistics
        sumMatches += matches

    matchesPlayed = sumMatches / 2
    sumMatches_div_playerCount = sumMatches / playerCount
    current_round = sumMatches_div_playerCount + 1
    next_round = current_round + 1

    round_complete = False
    if playerCount / 2 == matchesPlayed:
        #   is True only when all matches for last round are played
        #   is False during current_round
        round_complete = True

    return current_round, round_complete, next_round
def add_player(name=None):
    '''
    add_player(): Register a new Player for the current Tournament. The Player
    ID (PID) will be assigned by the dB. The Player's name is input by the user
    and verified to contain non-numeric characters.

    Argument: name - default = None

    Return: None - returns to main menu
    '''
    tid = getTid()

    if tid < 100:
        print 'Please "Select Tournament" from the main menu.'
        queryEnter()
        return

    print '''Tournament Manager supports an even numbers of players. This function will help you add two players at a time.'''.format()

    while True:
        # the name must be alphabetic characters only
        pname = verify_name()
        tour.registerPlayer(pname, tid)
        if tour.countPlayers(tid) % 2 != 0:
            continue
        else:
            break

    # display registered tournament players after entry
    display_players()
    return
def getRound(tid=100):
    '''
    getRound(): return the current round of the Tournament, if the last
    round is complete, and the next round

    Argument: tid

    Return: Tournament round, Boolean for last round complete, Tournament next round
    '''
    playerCount = tour.countPlayers(tid)

    # number of rounds in Swiss Pairing is based on number of players
    # need calculatedRounds to know when Tournament is finished
    #   i.e., current round > calculatedRounds
    calculatedRounds = int(ceil(log(playerCount, 2)))
    standings = tour.playerStandings(tid)
    sumMatches = 0
    for playerStatistics in standings:
        pid, name, wins, matches = playerStatistics
        sumMatches += matches

    matchesPlayed = sumMatches / 2
    sumMatches_div_playerCount = sumMatches / playerCount
    current_round = sumMatches_div_playerCount + 1
    next_round = current_round + 1

    round_complete = False
    if playerCount / 2 == matchesPlayed:
        #   is True only when all matches for last round are played
        #   is False during current_round
        round_complete = True

    return current_round, round_complete, next_round
def add_player(name=None):
    '''
    add_player(): Register a new Player for the current Tournament. The Player
    ID (PID) will be assigned by the dB. The Player's name is input by the user
    and verified to contain non-numeric characters.

    Argument: name - default = None

    Return: None - returns to main menu
    '''
    tid = getTid()

    if tid < 100:
        print 'Please "Select Tournament" from the main menu.'
        queryEnter()
        return

    print '''Tournament Manager supports an even numbers of players. This function will help you add two players at a time.'''.format(
    )

    while True:
        # the name must be alphabetic characters only
        pname = verify_name()
        tour.registerPlayer(pname, tid)
        if tour.countPlayers(tid) % 2 != 0:
            continue
        else:
            break

    # display registered tournament players after entry
    display_players()
    return
def testRegister():
    tournament.deleteMatches()
    tournament.deletePlayers()
    tournament.registerPlayer("Chandra Nalaar")
    c = tournament.countPlayers()
    if c != 1:
        raise ValueError("After one player registers, countPlayers() should be 1.")
    print("4. After registering a player, countPlayers() returns 1.")
 def number_of_players(self):
     """
     This sets the number of players in the tournament
     :return:
     """
     players = tournament.countPlayers(self.database, self.cursor)
     self.logger.info("Number of players " + str(players))
     self.numplayers = players
def testCount():
    tournament.deleteMatches()
    tournament.deletePlayers()
    c = tournament.countPlayers()
    if c == "0":
        raise TypeError("countPlayers() should return numeric zero, not string '0'.")
    if c != 0:
        raise ValueError("After deleting, countPlayers should return zero.")
    print("3. After deleting, countPlayers() returns zero.")
Exemplo n.º 10
0
def menu():
    """
        menu system for swiss pair tournament
    """
    choice = ""
    while choice != 'quit':
        print "What would you like to do: "
        print "1) add a player"
        print "2) start tournament"
        print "3) view  current players"
        print "4) reset database"
        print "Enter quit to exit"
        choice = raw_input("> ")
        if choice == '1':
            print "Enter a player's name:"
            name = raw_input("> ")
            if name != "" or name != " ":
                tournament.registerPlayer(name)
            else:
                print "Invalid name"
        elif choice == '2':
            numberOfPlayers = tournament.countPlayers()
            if numberOfPlayers < 6:
                print "Insufficient number of players. Tournament can \
                       not be started."
            else:
                print "Do you wish to start the tournament?"
                print "You will not be able to add anymore players if you do."
                print "Enter yes to continue and no to cancel."
                start = raw_input("> ")
                if start == 'yes':
                    choice = 'quit'
                    startTournamentMenu()
                else:
                    print "start of tournament cancelled"
        elif choice == '3':
            players = tournament.playerStandings()
            for i in players:
                print "player's name: {} id: {}".format(i[1], i[0])
        elif choice == '4':
            print " Are you sure you want to erase the database:(yes/no)"
            answer = raw_input("> ")
            if answer == 'yes':
                tournament.deleteMatches()
                tournament.deletePlayers()
            elif answer == 'no':
                print "Deletion of database cancelled"
            else:
                print "Invalid input {}.".format(answer)
        elif choice == 'quit':
            print "Exiting now...."
        else:
            print "Invalid entry"
def testCount():
    """
    Test for initial player count,
             player count after 1 and 2 players registered,
             player count after players deleted.
    """
    tournament.deleteMatches()
    tournament.deletePlayers()
    c = tournament.countPlayers()
    if c == '0':
        raise TypeError(
            "countPlayers should return numeric zero, not string '0'.")
    if c != 0:
        raise ValueError(
            "After deletion, countPlayers should return zero. Got {c}".format(
                c=c))
    print "1. countPlayers() returns 0 after initial deletePlayers() execution."
    tournament.registerPlayer("Chandra Nalaar")
    c = tournament.countPlayers()
    if c != 1:
        raise ValueError(
            "After one player registers, countPlayers() should be 1. Got {c}".
            format(c=c))
    print "2. countPlayers() returns 1 after one player is registered."
    tournament.registerPlayer("Jace Beleren")
    c = tournament.countPlayers()
    if c != 2:
        raise ValueError(
            "After two players register, countPlayers() should be 2. Got {c}".
            format(c=c))
    print "3. countPlayers() returns 2 after two players are registered."
    tournament.deletePlayers()
    c = tournament.countPlayers()
    if c != 0:
        raise ValueError("After deletion, countPlayers should return zero.")
    print "4. countPlayers() returns zero after registered players are deleted.\n5. Players can be registered and deleted."
Exemplo n.º 12
0
def testCount():
    """
    Test for initial player count,
             player count after 1 and 2 players registered,
             player count after 4 players reg and 2 assigned
             player count after players deleted.
    """
    deleteMatches()
    deletePlayers()
    deleteTournaments()
    c = countPlayers()
    if c == '0':
        raise TypeError(
            "countPlayers should return numeric zero, not string '0'.")
    if c != 0:
        raise ValueError("After deletion, countPlayers should return zero.")
    print ("1.  countPlayers() returns 0 after "
           "initial deletePlayers() execution.")
    registerPlayer("Chandra Nalaar")
    c = countPlayers()
    if c != 1:
        raise ValueError("After one player registers, countPlayers() should "
                         "be 1. Got {c}".format(c=c))
    print "2.  countPlayers() returns 1 after one player is registered."
    registerPlayer("Jace Beleren")
    c = countPlayers()
    if c != 2:
        raise ValueError("After two players register, countPlayers() should "
                         "be 2. Got {c}".format(c=c))
    print "3.  countPlayers() returns 2 after two players are registered."

    t1 = newTournament("Tournament 1")
    p1 = registerPlayer("Steinar Utstrand")
    p2 = registerPlayer("Donald Duck")
    assignPlayers(t1, p1, p2)
    c = countPlayers()
    if c != 4:
        raise ValueError("Even players not assigned to "
                         "tournament should be counted.")
    print ("4.  countPlayers() returns 4 when 2 of 4 players are assigned "
           "to tournament.")
    c = countPlayers(t1)
    if c != 2:
        raise ValueError("countPlayers(t_id) should only count players "
                         "assigned to given tournament")
    print ("5.  countPlayers(t_id) returns 2 when 2 of 4 players are assigned "
           "to given tournament id")

    deletePlayers()
    c = countPlayers()
    if c != 0:
        raise ValueError(
            "After deletion, countPlayers should return zero.")
    print ("6.  countPlayers() returns zero after registered players are "
           "deleted.\n7.  Player records successfully deleted.")
Exemplo n.º 13
0
def startTournamentMenu():
    """
        menu to update each match. To view the standings and the match line ups
    """

    currentLineUp = tournament.swissPairings()
    numberOfPlayers = tournament.countPlayers()
    totalMatchesPlayed = 0
    matchesPlayedThisRound = 0
    totalMatches = numberOfPlayers * (numberOfPlayers-1)
    print numberOfPlayers, totalMatches
    choice = ""
    while choice != 'quit':
        if matchesPlayedThisRound == numberOfPlayers/2:
            # checks to see if all the matches were played for the round
            currentLineUp = tournament.swissPairings()
            matchesPlayedThisRound = 0
            displayCurrentMatches()
        print "How would you like to proceed:"
        print "1) Display current matches"
        print "2) Display player's current standings"
        print "3) Update current matches"
        print "Enter quit to exit"
        if totalMatchesPlayed == totalMatches:
            player = getTopThree()
            print "tournament has ended"
            print "1st place winner is: {}".format(player.next())
            print "2nd place winner is: {}".format(player.next())
            print "3rd place winner is: {}".format(player.next())
            choice = 'quit'
        else:
            choice = raw_input("> ")
        if choice == '1':
            displayCurrentMatches(currentLineUp)
        elif choice == '2':
            displayStandings()
        elif choice == '3':
            updateMatches(currentLineUp)
        elif choice == 'quit':
            print "Exiting now"
        else:
            print "{} is an invalid choice, please try again".format(choice)