Esempio n. 1
0
 def __init__(self, player_list,gameType, pwin_dict):
     self.topScoreCard = ScoreCard(player_list)
     self.topPlayerQueue = PlayerQueue(player_list)
     self.gameType = gameType
     self.gameStats = GameStats(player_list)
    
     self.pwin_dict = pwin_dict
Esempio n. 2
0
class GameController(object):
    """
    Controls the game according to the State of Florida Regulations
    Accepts a player list in post starting order
    Example: ['a', 'b', 'c','d','e','f','g','h']
    Creates a TopScoreCard - to keep track of the score through the whole game
    Example: {'a': 0, 'c': 0, 'b': 0, 'e': 0, 'd': 3, 'f': 1}
    Creates a PlayerQueue  - a list of players in post order
    Example: ['a', 'b', 'c','d','e','f','g','h']
    Plays a series of 'point sets' between players until the 1st, 2nd 3rd, and 4th positions are filled with only one player in each position. The sequence of point sets makes up a 'game'. The conditions for how a point set is scored and what it takes to finish a point set depend on the type of game (Spectacular 7, or Spectacular 9), the number of tied players at particular positions, and how many points have been played. A series of games makes up a program - ie Matinee or evening program.
    Returns a positionList - a ranked dict of players based on their relative scores
    Example: {1: ['f'], 2: ['a'], 3: ['c'], 4: ['b'], 5: ['e','d'], 6: []}
    """
    FIRST_ALLOWED_TIED_POSITION = 5    
    
    def __init__(self, player_list,gameType, pwin_dict):
        self.topScoreCard = ScoreCard(player_list)
        self.topPlayerQueue = PlayerQueue(player_list)
        self.gameType = gameType
        self.gameStats = GameStats(player_list)
       
        self.pwin_dict = pwin_dict
        

    def play_game(self):
        #print self.topScoreCard.get_first_tied_position()
        while self.topScoreCard.has_ties() and self.topScoreCard.get_first_tied_position() < self.FIRST_ALLOWED_TIED_POSITION:
            tiedScoreCard = self.topScoreCard.get_first_tied_score_card()
            tiedPlayerQueue = self.topPlayerQueue.get_first_tied_player_queue(tiedScoreCard.get_score_card())
            number_tied = tiedScoreCard.get_number_of_players_on_scorecard()
            # Get the appropriate rules from the rules dictionary
            rules_dict = self.gameType.get_point_set_rules_dict(number_tied, tiedScoreCard.get_score_card())
            if number_tied == 8:
                # This is the starting point set and is played until there is a winner
                # This point set is always played and the final queue positions determine the 
                # rotation sequence for playing all the ties. Therfore, need to capture the
                # queue status at this point to drive all the other tie breakers
                point_set_rules = self.get_8_tied_point_set_rules(rules_dict)
                #self.topPlayerQueue. = PlayerQueue(PlayerQueue.getPlayerQueue())
            if number_tied == 7:
                point_set_rules = self.get_7_tied_point_set_rules(rules_dict)
            if number_tied == 6:
                point_set_rules = self.get_6_tied_point_set_rules(rules_dict)
            if number_tied == 5:
                point_set_rules = self.get_5_tied_point_set_rules(rules_dict)
            if number_tied == 4:
                point_set_rules = self.get_4_tied_point_set_rules(rules_dict)
            if number_tied == 3:
                point_set_rules = self.get_3_tied_point_set_rules(rules_dict)
            if number_tied == 2:
                point_set_rules = self.get_2_tied_point_set_rules(rules_dict)
            # Some tied conditions call for a knockout point playing sequence instead of standard
            if point_set_rules.get('rotation') == 'knockout':
                #print 'knockout'
                tiedPlayerQueue = KnockOutPlayerQueue(tiedPlayerQueue.getPlayerQueue())
                
            pointSetPlayer = PointSetPlayer()
            
            
            untied_score_card = pointSetPlayer.play_point_set(tiedScoreCard, tiedPlayerQueue, point_set_rules, self.gameStats, self.pwin_dict)
            self.topScoreCard = self.topScoreCard.incorporate_sub_score_card(untied_score_card)
            #print tiedScoreCard.get_score_card()
            #print self.topScoreCard.get_score_card()
        posList = self.topScoreCard.make_position_list()
        game_stats_data = self.gameStats.get_game_stats()
        ####################### TO DO ######################
        # Can update playerstats here using posList
        # also send points_played out to somewhere 
        #print self.gameStats.get_game_stats()
        return posList, game_stats_data
            
    def get_2_tied_point_set_rules(self, rules_dict):
        """
        {'2>=0':{'point_system':[1,2], 'rotation':'queue', 'endConditions':{'score':'all_scores_different'}}}
        """
        
        def end_condition_met_function(tied_score_card, points_played):
            if tied_score_card.all_scores_different() == True:
                return True
            return False
                  
        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 2}
        return point_set_rules_dict


    def get_3_tied_point_set_rules(self, rules_dict):
        """
        {'3>=0':{'point_system':[1,2], 'rotation':'queue', 'endConditions':{'point_and_score':[2,7],'score':'all_scores_different'}}}
        """
        def end_condition_met_function(tied_score_card, points_played):
            if (tied_score_card.get_high_score() >= rules_dict['endConditions']['point_and_score'][1] and points_played >= rules_dict['endConditions']['point_and_score'][0]) or (tied_score_card.all_scores_different() == True):
                return True
            return False
 
        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 2}
        return point_set_rules_dict                


        
    def get_4_tied_point_set_rules(self, rules_dict):
        """
        {'4>=0':{'point_system':[1,2], 'rotation':'knockout', 'endConditions':{'point_and_score':[1,7],'points_played':2}}}
        """
        
        def end_condition_met_function(tied_score_card, points_played):
            if (tied_score_card.get_high_score() >= rules_dict['endConditions']['point_and_score'][1] and points_played > rules_dict['endConditions']['point_and_score'][0]) or points_played == rules_dict['endConditions']['points_played']:
                return True
            return False
            
        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 2,'rotation':'knockout'}
        return point_set_rules_dict

        
    def get_5_tied_point_set_rules(self, rules_dict):
        """
        {'5=0':{'point_system':[1,2], 'rotation':'queue', 'endConditions':{'point_and_score':[1,4]}}}
        {'5>=1':{'point_system':[1,2], 'rotation':'queue', 'endConditions':{'point_and_score':[1,7]}}
        """
        
        def end_condition_met_function(tied_score_card, points_played):
            if (tied_score_card.get_high_score() >= rules_dict['endConditions']['point_and_score'][1] and points_played >= rules_dict['endConditions']['point_and_score'][0]):
                return True
            return False
            
        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 2}
        return point_set_rules_dict        


    def get_6_tied_point_set_rules(self, rules_dict):
        """
        {'6>=0':{'point_system':[1,2], 'rotation':'knockout', 'endConditions':{'point_and_score':[1,7],'points_played':3}}}
        """
        
        def end_condition_met_function(tied_score_card, points_played):
            if (tied_score_card.get_high_score() >= rules_dict['endConditions']['point_and_score'][1] and points_played > rules_dict['endConditions']['point_and_score'][0]) or points_played == rules_dict['endConditions']['points_played']:
                return True
            return False
            
        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 2,'rotation':'knockout'}
        return point_set_rules_dict
        
        


    def get_7_tied_point_set_rules(self, rules_dict):
        """
        {'7=0':{'point_system':[1,2], 'rotation':'queue', 'endConditions':{'point_and_score':[1,6]}}}
        {'7>=1':{'point_system':[1,2], 'rotation':'queue', 'endConditions':{'point_and_score':[1,7]}}}
        """
        
        def end_condition_met_function(tied_score_card, points_played):
            if (tied_score_card.get_high_score() >= rules_dict['endConditions']['point_and_score'][1] and points_played >= rules_dict['endConditions']['point_and_score'][0]):
                return True
            return False
            
        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 2}
        return point_set_rules_dict
        
        
    def get_8_tied_point_set_rules(self, rules_dict):
        """
        {'8>=0':{'point_system':[1,1,7,2], 'rotation':'queue', 'endConditions':{'point_and_score':[1,7]}}}
        """
        
        def end_condition_met_function(tied_score_card, points_played):
            if (tied_score_card.get_high_score() >= rules_dict['endConditions']['point_and_score'][1] and points_played > rules_dict['endConditions']['point_and_score'][0]):
                return True
            return False

        point_set_rules_dict = {'end_condition_function':end_condition_met_function,'initial_points': 1, 'threshold':8,'next_points':2}
        return point_set_rules_dict